sqlsqlitebetter-sqlite3

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


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.


Solution

  • 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 |