Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert the FULL Excel date serial format to Unix timestamp

I've seen lots of references to converting the "date" portion of the Excel serial date format, but everyone seems to skip the "time" portion of it.

Here is what I need to do:

I have an Excel file I'm importing. PHP in use.

I am encountering the Excel Date Serial format (dddddd.tttttt) and need to convert this to an entire Unix timestamp.

I've tried a few different things, but am getting hung up on how to do this in a fluid motion.

like image 517
timebinder Avatar asked Jun 23 '12 20:06

timebinder


People also ask

How do I convert a timestamp to a date and time in Excel?

Use this shortcut – Ctrl + ; (Control + semicolon) to insert the current date. Use this shortcut – Ctrl + Shift + ; (Control + Shift + semicolon) to insert the current time. Use this shortcut – Press the combination (Ctrl + ;) and (Ctrl + Shift + ;) to insert the current time and time.


1 Answers

Please use this formula to change from Excel date to Unix date, then you can use "gmdate" to get the real date in PHP:

UNIX_DATE = (EXCEL_DATE - 25569) * 86400

and to convert from Unix date to Excel date, use this formula:

EXCEL_DATE = 25569 + (UNIX_DATE / 86400)

After doing this formula into a variable, you can get the real date in PHP using this example:

$UNIX_DATE = ($EXCEL_DATE - 25569) * 86400;
echo gmdate("d-m-Y H:i:s", $UNIX_DATE);

Thanks.

like image 126
Ahmed Eissa Avatar answered Sep 20 '22 06:09

Ahmed Eissa