OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.3.5

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.3.5
    iconOceanBase Database
    SQL - V 4.3.5
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Use datetime functions in queries

    Last Updated:2026-04-09 02:53:54  Updated
    share
    What is on this page
    share

    Datetime data types that are frequently used in Oracle tenants include DATE, TIMESTAMP, and INTERVAL. For more information about the datetime data types, see SQL syntax (Oracle mode).

    Datetime functions frequently used in Oracle tenants to fetch the system time include SYSDATE() and SYSTIMESTAMP(). Their default formats are determined by the NLS_DATE_FORMAT and NLS_TIMESTAMP_FORMAT parameters. Functions for the INTERVAL data type include NUMTODSINTERVAL() and NUMTOYMINTERVAL(), which convert between numbers and intervals.

    • Example: Format the datetime display

      In an Oracle tenant, you can use the TO_CHAR() function to adjust the datetime display format. For example:

      obclient> select sysdate, to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') new_date from dual;
      +-----------+---------------------+
      | SYSDATE   | NEW_DATE            |
      +-----------+---------------------+
      | 01-APR-20 | 2020/04/01 22:17:07 |
      +-----------+---------------------+
      1 row in set
      
    • Example: Extract the year, month, day, hour, minute, and second values from a datetime value

      In an Oracle tenant, you can use the TO_CHAR() function to extract year, month, day, hour, minute, or second values from a datetime value. For example:

      obclient> SELECT sysdate
           , to_char(sysdate,'yyyy') d_year
           , to_char(sysdate,'mm') d_month
           , to_char(sysdate,'dd') d_day
           , to_char(sysdate,'hh24') d_hour24
           , to_char(sysdate,'mi') d_min
           ,to_char(sysdate,'ss') d_sec
           FROM dual;
      +-----------+--------+---------+-------+----------+-------+-------+
      | SYSDATE   | D_YEAR | D_MONTH | D_DAY | D_HOUR24 | D_MIN | D_SEC |
      +-----------+--------+---------+-------+----------+-------+-------+
      | 01-JUN-22 | 2022   | 06      | 01    | 17       | 12    | 10    |
      +-----------+--------+---------+-------+----------+-------+-------+
      1 row in set
      
    • Example: Perform addition and subtraction operations on datetime values

      In an Oracle tenant, you can directly add days to or subtract days from a datetime value. You can also perform addition and subtraction operations on datetime values by using the NUMTODSINTERVAL() or ADD_MONTHS() function.

      obclient> SELECT sysdate
      , sysdate+1                                 t0
      , sysdate + numtodsinterval(1,'hour')       t1
      , sysdate + numtodsinterval(1,'minute')     t2
      , sysdate + numtodsinterval(1,'second')     t3
      , add_months(sysdate, 1)                    t4
      , add_months(sysdate, -1)                   t5
      FROM dual\G
      *************************** 1. row ***************************
      SYSDATE: 01-JUN-22
      T0: 02-JUN-22
      T1: 01-JUN-22
      T2: 01-JUN-22
      T3: 01-JUN-22
      T4: 01-JUL-22
      T5: 01-MAY-22
      1 row in set
      
    • Example: interval-related datetime functions

      obclient> select sysdate, systimestamp
           ,numtoyminterval(100,'YEAR')    interval_year
           ,numtoyminterval(100,'MONTH')   interval_mon
           ,numtodsinterval(100,'DAY')     interval_day
           ,numtodsinterval(100,'HOUR')    interval_hour
           ,numtodsinterval(100,'MINUTE')  interval_min
           ,numtodsinterval(100,'SECOND')  interval_sec
           from dual \G
      *************************** 1. row ***************************
           SYSDATE: 01-JUN-22
      SYSTIMESTAMP: 01-JUN-22 05.12.58.432471 PM +08:00
      INTERVAL_YEAR: +000000100-00
      INTERVAL_MON: +000000008-04
      INTERVAL_DAY: +000000100 00:00:00.000000000
      INTERVAL_HOUR: +000000004 04:00:00.000000000
      INTERVAL_MIN: +000000000 01:40:00.000000000
      INTERVAL_SEC: +000000000 00:01:40.000000000
      1 row in set
      

    Previous topic

    Use string functions in queries
    Last

    Next topic

    Use type conversion functions in queries
    Next