scarhand
scarhand

Reputation: 4337

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?

Upvotes: 4

Views: 4306

Answers (1)

Anton Kovalenko
Anton Kovalenko

Reputation: 21517

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')

Upvotes: 11

Related Questions