I've looked for hours now. Everywhere I see examples of how to convert the Excel serial date number to UNIX_Date.
What I want to do is a PHP date("Y-m-d H:i:s") to convert it to Excel serial date number.
Example:
$php_date = date("Y-m-d H:i:s"); // "2019-04-18 11:57:25" at the time
and if I type this "2019-04-18 11:57:25" in Excel cell, and format it to show a number then Excel shows me "43573.4982060185" How to get this "43573.4982060185" in PHP?
EDIT: As per Morgan's answer bellow I have a function now that does this: EDIT 2: Added timezone set to get my local time, if anyone else needs this, set for your local timezone. List of supported timezones for PHP can be found here https://www.php.net/manual/en/timezones.php
function PHP_to_Excel() {
date_default_timezone_set("Europe/London");
$datetime = date("Y-m-d H:i:s");
$strdate = strtotime($datetime);
$excel_date = floatval(25569 + ($strdate / 86400));
return $excel_date;
}
The above function will return the correct serial number for the current local date and time.