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

喜欢而已 提交于 2019-12-07 12:24:14

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/14775012/i-need-the-sqlite-equivalent-of-mysql-for-working-with-unix-timestamps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!