chambito
chambito

Reputation: 3

Sqlite: select ('now') not works as expected

I want to get the current date as yyyy-MM-dd from SQLite, I use the following query:

***SELECT date('now')***

But instead of returning the current date, it returns the next day from today.

For example, today (2015-12-01) I run the query and it returns (2015-12-02).

What I did wrong?

Image running query + calendar

Upvotes: 0

Views: 60

Answers (1)

laalto
laalto

Reputation: 152817

sqlite date and time functions use UTC time zone internally. In UTC the date was already 2015-12-02.

If you want to use another timezone, you need to specify it explicitly, e.g.

select date('now','-05:00');

I'd suggest to use UTC millisecond timestamps in your database layer though and have the presentation logic such as date formatting with timezone adjustment in your app code.

Reference: https://www.sqlite.org/lang_datefunc.html

Upvotes: 2

Related Questions