Let me see
Let me see

Reputation: 5094

How to add time to a dateTime in sqlite?

I have a table and in the table there is a date creationDate. which stores the timestamp like this

2013-12-23 10:07:42
2013-12-23 10:14:11

Actually I was using the mysql2sqlite.sh script to convert the database from mysql to sqlite. and while converting database it reduced the time 5:30 from the creationDate column. It might be some GMT problem.

So now I want to update the timestamp and add 5 hours 30 minutes to each entry in the creationDate column.
I searched about it a lot but i didnt find the solution. So how can i do it in sqlite ?

Upvotes: 25

Views: 37270

Answers (1)

laalto
laalto

Reputation: 152817

You can use the sqlite date functions for simple math like this:

UPDATE tablename SET creationDate=DATETIME(creationDate, '+330 minutes');

Though usually it makes more sense to keep the database data in UTC and format to local timezone when displaying it.

Upvotes: 50

Related Questions