Using unambiguous dates and times

Dates in the format yyyy/mm/dd or yyyy-mm-dd are always recognized unambiguously as dates, regardless of the date_order setting. Other characters can be used as separators instead of '/' or '-'; for example, '?', a space character, or ','. You should use this format in any context where different users may be employing different date_order settings. For example, in stored procedures, use of the unambiguous date format prevents misinterpretation of dates according to the user's date_order setting.

Also, a string of the form hh:mm:ss:ssss is interpreted unambiguously as a time.

For combinations of dates and times, any unambiguous date and any unambiguous time yield an unambiguous date-time value. Also, the form yyyy-mm-dd hh.mm.ss.sss is an unambiguous date-time value. Periods can be used in the time only in combination with a date.

In other contexts, a more flexible date format can be used. SQL Anywhere can interpret a wide range of strings as dates. The interpretation depends on the setting of the database option date_order. The date_order database option can have the value MDY, YMD, or DMY (see SET OPTION statement). For example, the following statement sets the date_order option to DMY:

SET OPTION date_order = 'DMY' ;

The default date_order setting is YMD. The ODBC driver sets the date_order option to YMD whenever a connection is made. The value can still be changed using the SET TEMPORARY OPTION statement.

The database option date_order determines whether the string 10/11/12 is interpreted by the database as November 12, 2010; October 11, 2012; or November 10, 2012. The year, month, and day of a date string should be separated by some character (/, -, or space) and appear in the order specified by the date_order option.

The year can be supplied as either 2 or 4 digits. The value of the nearest_century option affects the interpretation of 2-digit years: 2000 is added to values less than nearest_century and 1900 is added to all other values. The default value of this option is 50. Thus, by default, 50 is interpreted as 1950 and 49 is interpreted 2049.

The month can be the name or number of the month. The hours and minutes are separated by a colon, but can appear anywhere in the string.

Notes
  • It is recommended that you always specify the year using the four-digit format.
  • With an appropriate setting of date_order, the following strings are all valid dates:
    99-05-23 21:35
    99/5/23
    1999/05/23
    May 23 1999
    23-May-1999
    Tuesday May 23, 1999 10:00pm
  • If a string contains only a partial date specification, default values are used to fill out the date. The following defaults are used:
    • year   This year

    • month   No default

    • day   1 (useful for month fields; for example, May 1999 will be the date 1999-05-01 00:00)

    • hour, minute, second, fraction   0