Search code examples
sqldateadd

Applying an dateadd SQL to all rows


So I've used a range of queries to try and add 23 hours to all dates in the column 'match_date' and have received a variation of errors from all of them including syntax errors and errors stating that stats.dateadd does not exist.

update dates
set match_date=dateadd(hh,23,match_date)
where match_id >='1'

Any ideas why?


Solution

  • I'm guessing you're using Oracle, and the dateadd function is not available. Try:

    update dates
    set match_date = match_date + interval '23' hour
    where match_id >= 1
    

    Alternatively, in SQL adding a number to a date adds that number in days. So you could also:

    update dates
    set match_date = match_date + 23.0/24
    where match_id >= 1