Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel/SQLite date serial numbers

How can I get SQLite to convert excel-type serial numbers to dates, e.g. I want the integer 40074 in a table to somehow get the date 18-Sept-2009?

The dates are already in SQLite.

like image 901
John Smith Avatar asked Feb 15 '26 14:02

John Smith


2 Answers

This seems to work:

sqlite> SELECT DATETIME((49400 * 3600 * 24) - 3014928000, 'unixepoch');
2009-09-18 00:00:00

Honestly, I just guess and checked on the constant there, but I'm sure there's simple math to back it up.

It looks like it works for dates earlier than the epoch as well, but I haven't tested it thoroughly.

like image 51
Mark Rushakoff Avatar answered Feb 18 '26 11:02

Mark Rushakoff


sqlite> SELECT DATE('1899-12-30', '+40074 days');
2009-09-18
like image 22
dan04 Avatar answered Feb 18 '26 12:02

dan04



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!