OceanBase logo

OceanBase

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

Product Overview
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

OceanBase

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

Product Overview
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 Call Interface

V2.1.0Enterprise Edition

  • What's New
  • Product Introduction
  • Install OBCI
  • Data types
  • Basic development procedure
  • Development example
  • Load balancing
  • Reference Functions
    • Connect, authorize, and initialize functions
    • Handle and descriptor functions
    • Bind, define, and describe functions
    • Statement functions
    • LOB functions
    • Transaction functions
    • Miscellaneous functions
    • String functions
    • Date and Datetime functions
    • Interval functions
    • Number functions
    • Terminate functions
    • Describe functions
    • Locale functions
    • Define functions
  • Full-link Diagnostic Trace
    • Full-link Diagnostic Trace
    • Full-link Diagnostic Trace of OBCI
    • Sample code

Download PDF

What's New Product Introduction Install OBCI Data types Basic development procedure Development example Load balancing Connect, authorize, and initialize functions Handle and descriptor functions Bind, define, and describe functions Statement functions LOB functions Transaction functions Miscellaneous functions String functions Date and Datetime functions Interval functions Number functions Terminate functions Describe functions Locale functions Define functions Full-link Diagnostic Trace Full-link Diagnostic Trace of OBCI Sample code
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 Call Interface
  3. V2.1.0
iconOceanBase Call Interface
V 2.1.0Enterprise Edition

Date and Datetime functions

Last Updated:2024-05-14 09:02:08  Updated
share
What is on this page
OCIDateSysDate
OCIDateToText
OCIDateFromText
OCIDateTimeToText
OCIDateTimeFromText
OCIDateTimeConstruct
OCIDateTimeGetTime
OCIDateTimeGetDate
OCIDateTimeGetTimeZoneOffset
OCIDateTimeAssign
OCIDateTimeCheck
OCIDateTimeCompare
Additional information
OCIDateTimeConvert
OCIDateTimeGetTimeZoneName
OCIDateTimeSysTimeStamp

folded

share

OCIDateSysDate

Purpose : You can call this function to get the current system date and time of the client.

Syntax :

sword OCIDateSysDate ( 
OCIError       *err,
OCIDate        *sys_date );

Parameters :

Parameter Description
err(IN/OUT) The error handle.
sys_date(OUT) The current system date and time of the client.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateToText

Purpose : You can call this function to convert a date type to a character string.

Syntax :

sword OCIDateToText ( 
OCIError                  *err, 
const OCIDate             *date,
const OraText             *fmt,
ub1                       fmt_length,
const OraText             *lang_name,
ub4                       lang_length,
ub4                       *buf_size,
OraText                   *buf );

Parameters :

Parameter Description
err(IN/OUT) The error handle.
date(IN) The date to be converted.
fmt(IN) The conversion format. If it is NULL or (text *) 0, the date is converted to a string in the default date format of DD-MON-YY.
fmt_length(IN) The length of the fmt parameter.
lang_name(IN) Specifies the language in which names and abbreviations for months and days are returned. The default language of the session is used if lang_name is NULL or ((text *) 0).
lang_length(IN) The length of the lang_name parameter.
buf_size(IN/OUT) The size of the buffer (IN). The size of the resulting string is returned by using this parameter (OUT).
buf(OUT) The buffer where the converted string is placed.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateFromText

Purpose : You can call this function to convert a string to a date type in the specified format.

Syntax :

sword OCIDateFromText ( 
OCIError           *err,
const OraText      *date_str,
ub4                d_str_length,
const OraText      *fmt,
ub1                fmt_length,
const OraText      *lang_name,
ub4                lang_length,
OCIDate            *date );

Parameters :

Parameter Description
err(IN/OUT) The error handle.
date_str(IN) The date to be converted.
d_str_length(IN) The size of the input string. The date_str parameter is considered as a string that ends with NULL if the length is -1.
fmt(IN) The conversion format. If fmt is a NULL pointer, the string must be in the DD-MON-YY format.
fmt_length(IN) The length of the fmt parameter.
lang_name(IN) Specifies the language in which names and abbreviations for months and days are returned. The default language of the session is used if lang_name is NULL.
lang_length(IN) The length of the lang_name parameter.
date(OUT) The date obtained by converting the given string.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeToText

Purpose : You can call this function to convert a given date to a string in the specified format.

Syntax :

sword OCIDateTimeToText ( 
void                *hndl,
OCIError            *err,
const OCIDateTime   *date,
const OraText       *fmt,
ub1                 fmt_length,
ub1                 fsprec,
const OraText       *lang_name,
size_t              lang_length,
ub4                 *buf_size,
OraText             *buf );

Parameters :

Parameter Description
hndl(IN) The OCI user session handle or environment handle. If the user session handle is passed, the conversion takes place in NLS_LANGUAGE and NLS_CALENDAR of the session. Otherwise, the default value is used.
err(IN/OUT) The error handle.
date(IN) The date to be converted.
fmt(IN) The conversion format. If fmt is a NULL pointer, the result must be in the default format of the DATETIME type.
fmt_length(IN) The length of the fmt parameter.
fsprec(IN) Specifies the fractional second precision.
lang_name(IN) Specifies the language in which names and abbreviations for months and days are returned. The default language of the session is used if lang_name is NULL.
lang_length(IN) The length of the lang_name parameter.
buf_size(IN/OUT) The size of the buffer (IN). The size of the converted string (the result of the conversion) is returned (OUT).
buf(OUT) The buffer where the converted string is placed.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeFromText

Purpose : You can call this function to convert a given string to Oracle datetime in the specified format.

Syntax :

sword OCIDateTimeFromText ( 
void               *hndl,
OCIError           *err,
const OraText      *date_str,
size_t             dstr_length,
const OraText      *fmt,
ub1                fmt_length,
const OraText      *lang_name,
size_t             lang_length,
OCIDateTime        *datetime );

Parameters :

Parameter Description
hndl(IN) The OCI user session handle or environment handle. If the user session handle is passed, the conversion takes place in NLS_LANGUAGE and NLS_CALENDAR of the session. Otherwise, the default value is used.
err(IN/OUT) The error handle.
date_str(IN) The input string to be converted to Oracle datetime.
dstr_length(IN) The size of the input string. The date_str parameter is considered as a string that ends with NULL if the length is -1.
fmt(IN) The conversion format. If fmt is a NULL pointer, the result must be in the default format of the DATETIME type.
fmt_length(IN) The length of the fmt parameter.
lang_name(IN) Specifies the language in which names and abbreviations for months and days are returned. The default language of the session is used if lang_name is NULL.
lang_length(IN) The length of the lang_name parameter.
datetime(OUT) The datetime obtained by converting the given string.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeConstruct

Purpose : You can call this function to construct a datetime descriptor.

Syntax :

sword OCIDateTimeConstruct ( 
void          *hndl,
OCIError      *err,
OCIDateTime   *datetime,
sb2           year,
ub1           month,
ub1           day,
ub1           hour,
ub1           min,
ub1           sec,
ub4           fsec,
OraText       *timezone,
size_t        timezone_length );

Parameters :

Parameter Description
hndl(IN) The OCI user session handle or environment handle.
err(IN/OUT) The error handle.
datetime(IN) The pointer to an OCIDateTime descriptor.
year(IN) The value for year.
month(IN) The value for month.
day(IN) The value for day.
hour(IN) The value for hour.
min(IN) The value for minute.
sec(IN) The value for second.
fsec(IN) The value for fractional second.
timezone(IN) The time zone string. The time zone offset of a particular time zone from GMT in the format of [[+|-][HH:MM]. For example: -08:00.
timezone_length(IN) The length of the time zone string.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeGetTime

Purpose : You can call this function to fetch the time (including the values for hour, minute, second, and fractional second) out of a datetime value.

Syntax :

void OCIDateTimeGetTime ( 
void          *hndl,
OCIError      *err,
OCIDateTime   *datetime,
ub1           *hour,
ub1           *min,
ub1           *sec,
ub4           *fsec );

Parameters :

Parameter Description
hndl(IN) The OCI user session handle or environment handle.
err(IN/OUT) The error handle.
datetime(IN) The pointer to an OCIDateTime descriptor.
hour(OUT) The value for hour.
min(OUT) The value for minute.
sec(OUT) The value for second.
fsec(OUT) The value for fractional second.

Return value : NULL.

OCIDateTimeGetDate

Purpose : You can call this function to fetch the date (including values for the year, month, and day) out of a datetime value.

Syntax :

void OCIDateTimeGetDate ( 
void               *hndl,
OCIError           *err,
const OCIDateTime  *datetime,
sb2                *year,
ub1                *month,
ub1                *day );

Parameters :

Parameter Description
hndl(IN) The OCI user session handle or environment handle.
err(IN/OUT) The error handle.
datetime(IN) The pointer to an OCIDateTime descriptor.
year(OUT) The value for year.
month(OUT) The value for month.
day(OUT) The value for day.

Return value : NULL.

OCIDateTimeGetTimeZoneOffset

Purpose : You can call this function to fetch the time zone (including values for the hour and minute) out of a datetime value.

Syntax :

void OCIDateTimeGetTimeZoneOffset ( 
void               *hndl,
OCIError           *err,
const OCIDateTime  *datetime,
sb1                *hour,
sb1                *min);

Parameters :

Parameter Description
hndl(IN) The OCI user session handle or environment handle.
err(IN/OUT) The error handle.
datetime(IN) The pointer to an OCIDateTime descriptor.
hour(OUT) The retrieved hour value of the time zone.
min(OUT) The retrieved minute value of the time zone.

Return value : NULL.

OCIDateTimeAssign

Purpose : You can call this function to assign a datetime.

Syntax :

sword OCIDateTimeAssign ( void                *hndl, 
OCIError            *err,
const OCIDateTime   *from,
OCIDateTime         *to );

Parameters :

Parameter Description
hndl (IN) The OCI user session handle or environment handle. If the user session handle is passed, the conversion takes place in NLS_LANGUAGE and NLS_CALENDAR of the session. Otherwise, the default value is used.
err (IN/OUT) The error handle. If any error occurs, it is recorded in err, and the function returns OCI_ERROR. You can call OCIErrorGet to obtain the diagnostic information.
from (IN) The source, namely the right side (rhs) of the datetime assignment.
to (OUT) The destination, namely the left side (lhs) of the datetime assignment.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeCheck

Purpose : You can call this function to check whether a given date is valid.

Syntax :

sword OCIDateTimeCheck ( void                *hndl,
OCIError            *err, 
const OCIDateTime   *date, 
ub4                 *valid );

Parameters :

Parameter Description
hndl (IN) The OCI user session handle or environment handle.
err (IN/OUT) The error handle. If any error occurs, it is recorded in err, and the function returns OCI_ERROR. You can call OCIErrorGet to obtain the diagnostic information.
date (IN) The date to be checked.
valid (OUT) Returns 0 if the date is valid.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeCompare

Purpose : You can call this function to compare two datetime values.

Syntax :

sword OCIDateTimeCompare ( void               *hndl,
OCIError           *err,
const OCIDateTime  *date1, 
const OCIDateTime  *date2,
sword              *result );

Parameters :

Parameter Description
hndl (IN) The OCI user session handle or environment handle.
err (IN/OUT) The error handle. If any error occurs, it is recorded in err, and the function returns OCI_ERROR. You can call OCIErrorGet to obtain the diagnostic information.
date1, date2 (IN) The dates to be compared.
result (OUT) The comparison result. For more information, see the table in the Additional information section.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

Additional information

Comparison result Output
date1<date2 -1
date1=date2 0
date1>date2 1

OCIDateTimeConvert

Purpose : You can call this function to convert a datetime variable to another type.

Syntax :

sword OCIDateTimeConvert ( void         *hndl,
OCIError     *err, 
OCIDateTime  *indate, 
OCIDateTime  *outdate );

Parameters :

Parameter Description
hndl (IN) The OCI user session handle or environment handle.
err (IN/OUT) The error handle. If any error occurs, it is recorded in err, and the function returns OCI_ERROR. You can call OCIErrorGet to obtain the diagnostic information.
indate (IN) The pointer to the input date.
outdate (OUT) The pointer to the output datetime.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeGetTimeZoneName

Purpose : You can call this function to obtain the name of the time zone from a datetime value.

Syntax :

sword OCIDateTimeGetTimeZoneName ( void               *hndl, 
OCIError           *err, 
const OCIDateTime  *datetime, 
ub1                *buf,
ub4                *buflen, );

Parameters :

Parameter Description
hndl (IN) The OCI user session handle or environment handle.
err (IN/OUT) The error handle. If any error occurs, it is recorded in err, and the function returns OCI_ERROR. You can call OCIErrorGet to obtain the diagnostic information.
datetime (IN) The pointer to an OCIDateTime descriptor.
buf (OUT) The buffer that stores the retrieved time zone name.
buflen (IN/OUT) The size of the buffer (IN), and the size of the name field (OUT).

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

OCIDateTimeSysTimeStamp

Purpose : You can call this function to obtain the current system date and time as a timestamp with a time zone.

Syntax :

sword OCIDateTimeSysTimeStamp ( void           *hndl,
OCIError       *err, 
OCIDateTime    *sys_date );

Parameters :

Parameter Description
hndl (IN) The OCI user session handle or environment handle.
err (IN/OUT) The error handle. If any error occurs, it is recorded in err, and the function returns OCI_ERROR. You can call OCIErrorGet to obtain the diagnostic information.
addend1 (IN) The pointer to the output timestamp.

Return value : OCI_SUCCESS is returned if the function call succeeded, and OCI_ERROR is returned if the function call failed.

Previous topic

String functions
Last

Next topic

Interval functions
Next
What is on this page
OCIDateSysDate
OCIDateToText
OCIDateFromText
OCIDateTimeToText
OCIDateTimeFromText
OCIDateTimeConstruct
OCIDateTimeGetTime
OCIDateTimeGetDate
OCIDateTimeGetTimeZoneOffset
OCIDateTimeAssign
OCIDateTimeCheck
OCIDateTimeCompare
Additional information
OCIDateTimeConvert
OCIDateTimeGetTimeZoneName
OCIDateTimeSysTimeStamp