Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite, how to use expression in datetime modifier

Tags:

sqlite

In short: I need to calculate the ending datetime given starting time and length in minutes.

I have a table with columns StartTime (type datetime) and LengthMinutes (type int). To calculate the ending time I would need some sql like this:

select datetime(StartTime, '+LengthMinutes minutes') from my_table;

How do I refer to the column LengthMinutes from within the modifier?

Edited: solved using dan04's suggestion. Thanks!

like image 269
Mats Avatar asked Oct 27 '25 12:10

Mats


2 Answers

SELECT datetime(StartTime, '+' || LengthMinutes || ' minutes') FROM my_table;
like image 147
dan04 Avatar answered Oct 29 '25 04:10

dan04


select datetime(strftime('%s',StartTime)+lengthMinutes*60,'unixepoch') from my_table;
like image 32
Phil Avatar answered Oct 29 '25 04:10

Phil