Date Conversion in Oracle

Source: Internet
Author: User

There are many date conversion functions in Oracle, and the common commands are as follows:

    • The To_char () command converts a timestamp to a user-specified date format, such as:

SELECT to_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') from DUAL;

Syntax: To_char (X [, format])

Description: Converts x into a string by format. X can be a date or a number or a timestamp, format is a formatted string that specifies what format to convert x

    • The to_date () command converts a string of date formats to date type data, such as:

SELECT to_date (' 2014-05-07 13:23:44 ', ' yyyy-mm-dd hh24:mi:ss ') from DUAL;

Syntax: To_date (C [, format])

Description: Converts a string C that conforms to a specific date format specified by format to a date type of data

    • The To_timestamp () function converts a time-formatted string to a timestamp

SELECT to_timestamp (' 2014-06-20 12:11:11 ', ' yyyy-mm-dd HH24:MI:SS ') from dual;

Syntax: To_timestamp (C [, format])

Description: Converts a string C to a timestamp data type

The---to_char () command converts a timestamp to a string:
Select To_char (To_timestamp (' 2014-06-20 12:11:11 ', ' yyyy-mm-dd HH24:MI:SS '), ' Yyyy-mm-dd HH24:MI:SS ') from dual;
    • When a comparison of two dates is required, no comparison time is required, and the date can be intercepted using the trunc () command

Sql> Select To_char (trunc (sysdate), ' Yyyy-mm-dd HH24:MI:SS ') from dual;
Sql> Select To_char (sysdate, ' Yyyy-mm-dd HH24:MI:SS ') from dual;

Date Conversion in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.