Convert excel decimal number into date

Nagesh Katke :

I have a number on which after applying some formula I got 43917.60417. Excel convert this number into date and datetime format as 3/27/2020 14:30:00. How can I convert this number into date or datetime using mysql or php. I searched a lot but didn't got any solution.

I tried

SELECT FROM_UNIXTIME(REPLACE('13577.77916', '.', ''));
 -- this results in 2013-01-10 06:01:56 
SELECT FROM_UNIXTIME(REPLACE('43917.60417', '.', '')); 
-- this results in null
Omari Victor Omosa :

Here you go in PHP

<?php

$unix = (43917.60417 - 25569) * 86400; //convert to unix first

echo gmdate("d-m-Y H:i:s", $unix); //return to your desired date format

?>

AND IN MySQL, This should work for both positive and negative epoch

SELECT DATE_ADD(FROM_UNIXTIME(0), interval (13577.77916-25569)*86400 second);

And to specify date format in MySQL, you can use DATE_FORMAT(

SELECT DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), interval (13577.77916-25569)*86400 second),'%Y-%m-%d') as my_new_date;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=13880&siteId=1