Background documentationDate and Time Calculations Locate this document in the navigation structure

 

To facilitate the calculation of dates and times, a series of functions are available that can use values of these data types to perform calculations.

Prerequisites

You can use the demo data for the SQL tutorial. Start the Database Studio as database administrator MONA with the password RED and log on to demo database DEMODB: Logging On to a Database.

Activities

You can use Database Studio to enter and execute SQL statements. More information: Working with SQL Statements: Overview

SELECT arrival, ADDDATE (arrival,2) new_arrival, rno

  FROM hotel.reservation

    WHERE rno = 130

Postponing the reservation date by two days

Result

ARRIVAL

NEW_ARRIVAL

RNO

2005-02-01

2005-02-03

130

SELECT arrival, departure, DATEDIFF(departure, arrival) overnight_stays, rno

  FROM hotel.reservation

    WHERE rno = 130

Number of overnight stays

Result

ARRIVAL

DEPARTURE

OVERNIGHT_STAYS

RNO

2005-02-01

2005-02-03

2

130

More Information

SQL Reference Manual, Date Function (date_function), Time Function (time_function), Extraction (extraction_function)

A variety of date formats (EUR, INTERNAL, ISO, JIS and USA) are available for processing date values.

SQL Reference Manual, Date and Time Format (datetimeformat)

More examples for Data Query