Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timezone in SQLite?

I have a such query to database:

SELECT * FROM screenings WHERE time(time)>time('now') ORDER BY time(time);

It works fine when the time zone is set to GMT+0:00. But if timezone has a different meaning (for example, GMT+6:00), database query results are in accordance with the GMT+0:00 and, respectively, the displayed information does not match the current time.

So, my question is how to set the local timezone in SQLite?

Thanks.

like image 964
Mark Korzhov Avatar asked Oct 13 '25 00:10

Mark Korzhov


2 Answers

Don't store values with timezone in the first place. Instead, normalize your data to UTC and use UTC consistently in your queries.

Only when formatting the data for display purposes, adjust for user's local timezone.

like image 150
laalto Avatar answered Oct 14 '25 15:10

laalto


Save data in UTC Timezone. when you need to display then fetch data then convert into user's Timezone

like image 32
Palak Avatar answered Oct 14 '25 14:10

Palak