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 Database

SQL - V4.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    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.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • 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

    STR_TO_DATE

    Last Updated:2026-04-14 12:43:57  Updated
    Share
    What is on this page
    Syntax
    Purpose
    Examples

    folded

    Share

    Syntax

    STR_TO_DATE(str, format)
    

    Purpose

    STR_TO_DATE() converts str into a DATETIME, DATE, or TIME value based on format. The return value type depends on the parts of the date and time that are included in format.

    • If str or format is NULL, this function returns NULL.

    • If str is not a valid date, the return value varies with the settings of sql_mode:

      • If sql_mode contains NO_ZERO_IN_DATE, NULL is returned.

      • If sql_mode does not contain NO_ZERO_IN_DATE:

        • If str is an integer, and str < 0, it returns 0000-00-00 00:00:00 and displays a warning prompt.

             obclient> SELECT STR_TO_DATE(-100,'%Y-%b-%D %r');
             +---------------------------------+
             | STR_TO_DATE(-100,'%Y-%b-%D %r') |
             +---------------------------------+
             | 0000-00-00 00:00:00             |
             +---------------------------------+
             1 row in set, 1 warning
          
        • If str is an integer and 0 ≤ str ≤ 69, it returns the year of the sum of 1999-11-30 00:00:00 plus str.

             obclient> SELECT STR_TO_DATE(0,'%Y-%b-%D %r');
             +------------------------------+
             | STR_TO_DATE(0,'%Y-%b-%D %r') |
             +------------------------------+
             | 1999-11-30 00:00:00          |
             +------------------------------+
             1 row in set
          
        • If str is an integer and 69 < str ≤ 99, it returns the year of the result of 1969-11-30 00:00:00 plus str minus 70.

             obclient> SELECT STR_TO_DATE(88,'%Y-%b-%D %r');
             +-------------------------------+
             | STR_TO_DATE(88,'%Y-%b-%D %r') |
             +-------------------------------+
             | 1987-11-30 00:00:00           |
             +-------------------------------+
             1 row in set
          
        • If str is an integer and 100 < str ≤ 9999, it returns the year of the result of 0099-11-30 00:00:00 plus str minus 100.

             obclient> SELECT STR_TO_DATE(2088,'%Y-%b-%D %r');
             +---------------------------------+
             | STR_TO_DATE(2088,'%Y-%b-%D %r') |
             +---------------------------------+
             | 2087-11-30 00:00:00             |
             +---------------------------------+
             1 row in set
          
        • If str is an integer, and str > 10000, it returns NULL and displays a warning prompt.

             obclient> SELECT STR_TO_DATE(10001,'%Y-%b-%D %r');
             +----------------------------------+
             | STR_TO_DATE(10001,'%Y-%b-%D %r') |
             +----------------------------------+
             | NULL                             |
             +----------------------------------+
             1 row in set, 1 warning
          
        • If str is a string, the function converts the string to a datetime if possible, and returns the result of the datetime value of str plus 1999-11-30 00:00:00. If str cannot be converted to a datetime, NULL is returned.

             obclient> SELECT STR_TO_DATE('a2014-Jan-1st 5:5:5 pm', '%Y-%b-%D %r');
             +------------------------------------------------------+
             | STR_TO_DATE('a2014-Jan-1st 5:5:5 pm', '%Y-%b-%D %r') |
             +------------------------------------------------------+
             | NULL                                                 |
             +------------------------------------------------------+
             1 row in set, 1 warning
          
             obclient> SELECT STR_TO_DATE('a2014-Jan-1st 5:5:5 pm', 'a%Y-%b-%D %r');
             +-------------------------------------------------------+
             | STR_TO_DATE('a2014-Jan-1st 5:5:5 pm', 'a%Y-%b-%D %r') |
             +-------------------------------------------------------+
             | 2014-01-01 05:05:05                                   |
             +-------------------------------------------------------+
             1 row in set
          
        • If str is neither an integer nor a string, it returns NULL and displays a warning prompt.

             obclient> SELECT STR_TO_DATE(1.6,'%Y-%b-%D %r');
             +--------------------------------+
             | STR_TO_DATE(1.6,'%Y-%b-%D %r') |
             +--------------------------------+
             | NULL                           |
             +--------------------------------+
             1 row in set, 1 warning
          
             obclient> SELECT STR_TO_DATE(pi(),'%Y-%b-%D %r');
             +---------------------------------+
             | STR_TO_DATE(pi(),'%Y-%b-%D %r') |
             +---------------------------------+
             | NULL                            |
             +---------------------------------+
             1 row in set, 1 warning
          

    For more information about the formats supported by format, see DATE_FORMAT.

    Examples

    obclient> SELECT STR_TO_DATE('2014-Jan-1st 5:5:5 pm', '%Y-%b-%D %r');
    +-----------------------------------------------------+
    | STR_TO_DATE('2014-Jan-1st 5:5:5 pm', '%Y-%b-%D %r') |
    +-----------------------------------------------------+
    | 2014-01-01 05:05:05                                 |
    +-----------------------------------------------------+
    1 row in set
    

    Previous topic

    SECOND
    Last

    Next topic

    SUBDATE
    Next
    What is on this page
    Syntax
    Purpose
    Examples