Search code examples
sqltimestampverticadbeaver

Add and subtract 1 hour from Timestamp column in DBeaver (SQL)


I have a table with the column 'Timestamp'. I want to create 2 columns that contains the -1hour and +1hour of that time stamp.

This is the format of the timestamp: 2020-08-31 11:05:55 and I want to get 2 more columns showing the -1hour and +1hour: 2020-08-31 10:05:55 and 2020-08-31 12:05:55

Thanks!


Solution

  • In standard ANSI SQL you can simply subtract an interval:

    select the_column - interval '1' hour as one_hour_before,
           the_column, 
           the_column + interval '1' hour as one_hour_after
    from the_table
    where ....