Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need the SQLite equivalent of MySQL for working with unix timestamps

I'm using unix timestamps with SQLite and storing them as an integer. My problem is that I am trying to select records for today based on their unix timestamps and I have no clue what functions to use.

Here is what I would use in MySQL:

where date_format(from_unixtime(COLUMN_DATE), '%Y-%m-%d')= date_format(now(), '%Y-%m-%d')

However when I try to use these functions I'm getting errors in the log telling me they don't exist for SQLite.

How do I write this for SQLite?

like image 256
scarhand Avatar asked Nov 15 '25 02:11

scarhand


1 Answers

SQLite date and time functions are documented at http://sqlite.org/lang_datefunc.html.

The equivalent of your WHERE clause would be

WHERE date(COLUMN_DATE,'unixepoch') = date('now')
like image 77
Anton Kovalenko Avatar answered Nov 17 '25 19:11

Anton Kovalenko