Use time function with the date 2019-04-01 to add 2 hours to the time using sqlite3

711 Views Asked by At

I am trying to writing sql in sqlite3 but somehow it is not passing the result . I tried this :

select datetime ('2019-04-01 12:20',time('+2 hours'));

or

select time ('2019-04-01 12:20','+2 hours');

or

select date ('2019-04-01','YYYY-MM-DD HH:MM',time('+2 hours'));

any suggestions will be appreciated.

3

There are 3 best solutions below

0
On BEST ANSWER

You should try to add minutes as following

select DATETIME('2019-04-01 12:20', '+120 minutes') as newTime;

or

select DATETIME('2019-04-01 12:20', '+2 hours') as newTime;

output:

| newTime             |
| ------------------- |
| 2019-04-01 14:20:00 |
0
On

You just need datetime() function with modifier containing hours such as

select datetime ('2019-04-01 12:20','+2 hours');
0
On

You can do like below:

SELECT time('2019-04-01','+2 hours');