DATE

The DATE function returns a date from a value.

Syntax

DATE ( expression )

expression

An expression that can be any of the following:

  • A  LONG VARCHAR value, which must represent a valid date in the form yyyynnn, where yyyy is a four-digit year value, and nnn is a three-digit day value in the range 001 to 366.

Results

The returned result is governed by the following rules:

  • If the argument can be NULL, the result can be NULL; if the argument is NULL, the result is the NULL value.
  • If the argument is a date, timestamp, or valid string representation of a date or timestamp, the result is the date part of the value.
  • If the argument is a number, the result is the date that is n-1 days after January 1, 1970, where n is the integral part of the number.
  • If the argument is a string with a length of 7, the result is a string representation of the date.

Examples

This example results in an internal representation of ‘1988-12-25’.

splice> VALUES DATE('1988-12-25');

This example results in an internal representation of ‘1972-02-28’.

splice> VALUES DATE(789);

This example illustrates using date arithmetic with the DATE function:

splice> select Birthdate - DATE('11/22/1963') AS "DaysSinceJFK" FROM Players WHERE ID < 20;
DaysSinceJ&
-----------
8526
8916
9839
8461
9916
6619
6432
7082
7337
7289
9703
5030
9617
6899
9404
7446
7609
9492
9172

19 rows selected

See Also