Skip to main content

Date and Time Values

Date and Time Values

This section provides a quick overview of date and time values in ObjectScript.

Local Time

To access the date and time for the current process, you use the $HOROLOG special variable. Because of this, in many Caché applications, dates and times are stored and transmitted in the format used by this variable. This format is often called $H format or $HOROLOG format.

$HOROLOG retrieves the date and time from the operating system and is thus always in the local time zone.

The Caché class library includes data type classes to represent dates in more common formats such as ODBC, and many applications use these instead of $H format.

UTC Time

Caché also provides the $ZTIMESTAMP special variable, which contains the current date and time as a Coordinated Universal Time value in $H format. This is a worldwide time and date standard; this value is very likely to differ from your local time (and date) value.

Date and Time Conversions

ObjectScript includes functions for converting date and time values.

  • Given a date in $H format, the function $ZDATE returns a string that represents the date in your specified format.

    For example:

    SAMPLES>WRITE $ZDATE($HOROLOG,3)
    2010-12-03
    
  • Given a date and time in $H format, the function $ZDATETIME returns a string that represents the date and time in your specified format.

    For example:

    SAMPLES>WRITE $ZDATETIME($HOROLOG,3)
    2010-12-03 14:55:48
    
  • Given string dates and times in other formats, the functions $ZDATEH and $ZDATETIMEH convert those to $H format.

  • The functions $ZTIME and $ZTIMEH convert times from and to $H format.

Details of the $H Format

The $H format is a pair of numbers separated by a comma. For example: 54321,12345

  • The first number is the number of days since December 31st, 1840. That is, day number 1 is January 1st, 1841. This number is always an integer.

  • The second number is the number of seconds since midnight on the given day.

    Some functions, such as $NOW(), provide a fractional part.

For additional details, including an explanation of the starting date, see $HOROLOG in the Caché ObjectScript Reference.

FeedbackOpens in a new tab