Using PHP, I need to extract encoded datetime values from a SQLite database for display on a web page. The datetime are encoded in a custom format, as described in this question.
However, my code is only extracting the date part and not the time part.
This is my code:
function convert_datetime_database_to_php ($database_datetime)
{
$php_datetime = bcsub(bcdiv($database_datetime, 864000000000), 693593);
$php_datetime = bcmul(bcsub($php_datetime, 25569), 86400);
$php_datetime = gmdate('Y-m-d g:i A', $php_datetime);
return $php_datetime;
}
Below are the actual datetime values stored in the database, and the equivalent date/time value after conversion (from Delphi code):
- 637911704796343035 = 6/18/2022 5:34:39 PM
- 637911809759649501 = 6/18/2022 8:29:35 PM
However the PHP code will return "2022-06-18 12:00 AM" for both above values, skipping the conversion of the time part.
What is wrong with my PHP code and how can I correctly extract the time part?