I have SQLite DB one table contains datetime field
with datatype "timestamp" REAL value is 18696.0
attach image for table structure
So, I want this 18696.0 value to be converted into MySQL Y-m-d format and result should be 2021-03-10
I have didn’t found any solution online. any help would be appreciated.
SQLite timestamp converted into MySQL timestamp.
3
Answers
Try this:
Output:
1970-01-01 04:58:09
EDIT: Thankyou for updating your question with the correct number and what date it should represent.
You can achieve what you need with a function that adds the days onto the Unix Epoch date:
SQLite dates stored in
REAL
data type stores dates as a Julian Day.From https://www.sqlite.org/datatype3.html
PHP has a
jdtogregorian
function, in which one comment has a handy function to convert to ISO8601 dates:The results don’t exactly look right, is it definitely 17889.0 in SQLite?
If this float number 18696.0 represents the number of days since 1970-01-01 then the date can also be calculated like this:
background information
Or simply with gmdate:
The days are simply converted into seconds to get a valid timestamp for gmdate.