Home> Database> Oracle> body text

Usage of to_date in oracle

下次还敢
Release: 2024-05-02 23:40:00
Original
817 people have browsed it

The TO_DATE function in Oracle can convert a string to the DATE data type. Syntax: TO_DATE(string, format_mask). format_mask is a placeholder mask that specifies the format of the date and time portion of the string. Placeholders include YYYY (year), MM (month), DD (day), HH (hour), MI (minute), SS (second), FF (billionth of a second). For example, TO_DATE('2023-03-08', 'YYYY-MM-DD') converts "2023-03-08" to DATE.

Usage of to_date in oracle

Usage of TO_DATE function in Oracle

The TO_DATE function in Oracle is used to convert strings to DATE data type.

Syntax:

TO_DATE(string, format_mask)
Copy after login

Where:

  • string:The string to be converted.
  • format_mask:Mask string specifying the string format.

Format mask:

The format mask uses the following placeholders to specify the date and time parts:

Placeholder Description
YYYY Four-digit year
MM two-digit month
DD Two-digit day
HH Two-digit hour (00-23)
MI Two-digit minutes (00-59)
SS Two-digit seconds (00-59)
FF billionth of a second

Example:

  • Convert "2023-03-08" string to DATE:
TO_DATE('2023-03-08', 'YYYY-MM-DD')
Copy after login
  • Convert the string "2023-03-08 14:30:15" to DATE:
TO_DATE('2023-03-08 14:30:15', 'YYYY-MM-DD HH24:MI:SS')
Copy after login
  • Convert the string "08/03/2023 02:30 PM" to DATE:
TO_DATE('08/03/2023 02:30 PM', 'MM/DD/YYYY HH:MI PM')
Copy after login

Note:

  • The format mask must match the format of the string, otherwise an error will occur.
  • TO_DATE function returns NULL if the string cannot be converted to the DATE data type.

The above is the detailed content of Usage of to_date in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!