Home > Database > Oracle > body text

Which function is used to convert string to date in Oracle?

下次还敢
Release: 2024-05-08 17:57:17
Original
772 people have browsed it

The function in Oracle that converts a string into the DATE data type is the TO_DATE function. The usage is as follows: TO_DATE(string_expression, format_mask)string_expression: The string value to be converted. format_mask: A mask that specifies the format of the date/time component in a string.

Which function is used to convert string to date in Oracle?

Function to convert string to date in Oracle: TO_DATE

TO_DATE function converts string value to DATE data type. The syntax is as follows:

<code>TO_DATE(string_expression, format_mask)</code>
Copy after login

Parameters:

  • string_expression: The string expression to be converted.
  • format_mask: A string specifying the format of the date/time components in the string.

Usage:

When using the TO_DATE function to convert a string to the DATE type, you need to specify format_mask to indicate the date in the string /The format of the time component. For example:

<code>TO_DATE('2023-01-01', 'YYYY-MM-DD')</code>
Copy after login

This will convert the string "2023-01-01" to the DATE type with the format "YYYY-MM-DD".

Common format masks:

Common date/time format masks in Oracle include:

  • YYYY-MM-DD: Year-Month-Day
  • MM/DD/YYYY: Month/Day/Year
  • HH24:MI:SS: 24-hour time
  • HH:MI AM: 12 Hourly time (morning)
  • HH:MI PM: 12-hour time (afternoon)

Example:

  • Convert the string "2023-03-15" to the DATE type, in the format "YYYY-MM-DD":
<code>TO_DATE('2023-03-15', 'YYYY-MM-DD')</code>
Copy after login
  • Convert the string "12:30 PM" to DATE Type, the format is "HH:MI AM/PM":
<code>TO_DATE('12:30 PM', 'HH:MI AM')</code>
Copy after login

The above is the detailed content of Which function is used to convert string 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
Popular Tutorials
More>
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!