Rashad.Z
Rashad.Z

Reputation: 2604

Difference Between DateTime( 'now', 'localtime' ) and DateTime( 'now') SQLITE

i always use DateTime('now') to store the current time that the query execution took place, but recently i faced a problem with this which is the time is saving in GMT (or other than the phone's current time) but also i noticed that this effect ( wrong date) is not happening in all my tables (which all have a defualt value of DateTime( 'now')..)

my question is if i have a column date time in my database and want to have a default value for the current time on the phone (when query execution took place) should i always use DateTime( 'now', 'localtime' ) as a default value for date column ?

Thank you.

Upvotes: 1

Views: 4342

Answers (1)

CL.
CL.

Reputation: 180070

datetime('now') returns what your device thinks what the current time in GMT is.

datetime('now', 'localtime') returns what your device thinks what the current time in what the device thinks what the current time zone is.

In general, storing times in GMT is preferred because you do not have to bother with changing time zones.

Upvotes: 3

Related Questions