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 function in Oracle
The TO_DATE function in Oracle is used to convert strings to DATE data type.
Syntax:
TO_DATE(string, format_mask)
Where:
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:
TO_DATE('2023-03-08', 'YYYY-MM-DD')
TO_DATE('2023-03-08 14:30:15', 'YYYY-MM-DD HH24:MI:SS')
TO_DATE('08/03/2023 02:30 PM', 'MM/DD/YYYY HH:MI PM')
Note:
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!