All Products
Document Center

DATE data type

Last Updated: Jun 18, 2021

The DATE data type stores the date and time information. Although you can use both character and numeric data types to represent the date and time information, the DATE data type has special associated properties.timetime For each DATE value, ApsaraDB for OceanBase stores the information about year, month, day, hour, minute, and second, but does not contain the time zone information.time zoneinfo


NLS_DATE_FORMAT determines the default input and output formats of the DATE data type. Run the following SQL statement to query the default format:


Return result:


To customize data formats, you can use conversion functions. When you insert data, you can use the TO_DATE(char,fmt) function to specify the input format of the data. When you query data, you can use the TO_CHAR(datetime,fmt) function to specify the output format of the data. These two conversion functions convert a string to the format defined by the fmt parameter. If you do not specify fmt, the default format is used.


The DATE data type stores the time information such as the hour, minute, and second. However, the default format does not contain the time information.

Value range

0001-01-01 00:00:00~9999-12-31 23:59:59


  • Example 1: This example returns the current system date. Assume that you do not specify the fmt parameter, the TO_CHAR function returns a value in the default format of the data type.

Return result:

| 24-FEB-20        |

  • Example 2: Assume that you do not specify the DATE value as a literal, the database returns the system default value:
    • Year: indicates the current year, which is returned by SYSDATE.

    • Month: indicates the current month, which is returned by SYSDATE.

    • Day: defaults to 01 that indicates the first day of the current month.

    • The hour, minute, and second values are all 0.

This example uses the TO_DATE(string,format) function to insert date data. TO_DATE converts the characters in the string parameter to a value in the format specified in the format parameter.

Assume that you issue the following query in February 2020:


Return result:

| TO_CHAR(TO_DATE('2020', 'YYYY'),'YYYY-MM-DD HH24:MI:SS') |
|                                       2020-02-01 00:00:00|