Caché SQL Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   

A scalar date/time function that returns the current local date.
{fn CURDATE()}
CURDATE takes no arguments and returns the date as type DATE. Note that the argument parentheses are optional. CURDATE returns the current local date for this timezone; it adjusts for local time variants, such as Daylight Saving Time.
CURDATE in Logical mode returns the current local date in $HOROLOG format; for example, 62970. CURDATE in Display mode returns the current local date in the default format for the locale. For example, in an American locale 05/28/2013, in a European locale 28/05/2013, in a Russian locale 28.05.2013.
To specify a different date format, use the TO_DATE function. To change the default date format, use the SET OPTION command with the DATE_FORMAT, YEAR_OPTION, or DATE_SEPARATOR options.
To return just the current date, use CURDATE or CURRENT_DATE. These functions return their values in DATE data type. The CURRENT_TIMESTAMP, GETDATE and NOW functions can also be used to return the current date and time as a TIMESTAMP data type.
Note that all Caché SQL time and date functions except GETUTCDATE are specific to the local time zone setting. To get a current timestamp that is universal (independent of time zone) you can use GETUTCDATE or the ObjectScript $ZTIMESTAMP special variable.
These data types perform differently when using embedded SQL. The DATE data type stores values as integers in $HOROLOG format; when displayed in SQL they are converted to date display format; when returned from embedded SQL they are returned as integers. A TIMESTAMP data type stores and displays its value in the same format. You can use the CONVERT function to change the data type of dates and times.
The following examples both return the current date:
The following Embedded SQL example returns the current date. Because this date is stored in $HOROLOG format, it is returned as an integer:
  &sql(SELECT {fn CURDATE()} INTO :a)
  WRITE !,"Current date is: ",a
The following example shows how CURDATE can be used in a SELECT statement to return all records that have a shipment date that is the same or later than today's date:
     WHERE ShipDate >= {fn CURDATE()}
See Also