Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Date/Time Manipulation

Tags:

sqlite

I'm looking at doing some basic date/time manipulation using SQLite however the documentation isn't very clear. All I want to do is add some minutes that already exist in the same row in the database. I have a datetime, and then a duration. So I want to get the start date/time as well as the end date/time. I've looked at something along these lines:

I see you can use datetime, but you have to specify a 'localtime' which doesn't seem to work.

Basically, I want the equivalent of DATEADD in SQL Server.

like image 854
Kezzer Avatar asked Jul 09 '11 08:07

Kezzer


2 Answers

This is how you add 15 minutes to the current datetime.

SELECT datetime('now', '+15 Minute');
like image 98
naveen Avatar answered Sep 22 '22 18:09

naveen


Try

datetime(strftime('%s', start_date) + minute_count * 60,  'unixepoch')

start_date – your start date;

minute_count – count of minutes as integer.

like image 41
Gedrox Avatar answered Sep 21 '22 18:09

Gedrox