I have birth dates stored in a MySQL database that I need converted to a readable date format yyyy-mm-dd hh:mm:ss
. I cannot use the MySQL's From_Unix function as many birth dates are before 1970 and the function returns NULL
. (i.e. -866138400000 which is 07/21/1942)
I have tried to use ticks but that is also returning NULL
:
(FROM_DAYS(365 + (req.PATIENTDOB / 864000000000)) + INTERVAL (req.PATIENTDOB % 864000000000) / 10000000 SECOND) AS ptDob
Any advance would be greatly appreciated. Thank you.
I have no idea why you're making things so complicated. Just divide by 1000 to get seconds instead of microseconds and subtract that from 1970-01-01.
So your query would actually be this of course:
This query proves, that your assumption, that it would be 1942-07-21 is wrong. 1942-07-22 is correct.