Formatting Considerations
- The format string can be any combination of characters and format patterns for each function specified in the Date and Timestamp Formatting Patterns and Date and Timestamp Formatting Modifiers tables.
- Patterns can be uppercase or lowercase, but not mixed case. YYYY or yyyy matches YYYY, but not YyYy.
- Any characters in the format string that are not part of a pattern match any character in that position in TO_DATE, TO_NUMBER, and TO_TIMESTAMP.
- You can escape string literals that contain format patterns with quotes. For example:
YYYY"a literal part YYYY"
Date and Time Formatting Functions
Date and Timestamp Formatting Patterns
The following modifiers can also be applied to a format pattern.
Date and Timestamp Formatting Modifiers
Date and Time notes
- You can use time specifiers such as HH12 in
TO_DATE. Their format will be validated, but their values will not affect the resulting date. - ISO 8601 formats for dates cannot be mixed with traditional formats for years, months, and days in
TO_DATEandTO_TIMESTAMP - Values for MS, US, and NS are scaled up if they do not have leading zeros.
TO_TIMESTAMP('0.3', 'S.NS')corresponds to 300000000 NS andTO_TIMESTAMP('0.000000003', 'S.NS')corresponds to 3 NS. - Conflicting information for the same pattern will cause an exception. ex:
TO_DATE('05 31', 'DD DD') - Conflicting information across different patterns such as DD and DDD will generally give precedence to the pattern that appears higher in the table.
TO_TIMESTAMP
Converts a character value with the specified format to aTIMESTAMP type.
Syntax
SQL
Examples
SQL
2022-12-01 00:00:00.000
SQL
2023-02-28 13:43:20.000
TO_DATE
Converts a character value with the specified format to aDATE type.
Syntax
SQL
Example
SQL
2022-12-01
Number Formatting Functions
Number Formatting Patterns
Number Formatting Notes
- You cannot mix PR with other sign indicators.
- Any character that does not match the corresponding group in the format string is ignored.
TO_NUMBER('1&2', '999')= 12. - If PR is present, it must be after every 0 or 9 in the format string.
- Similar to TO_DATE and TO_TIMESTAMP, the FM is not considered a literal, but will not otherwise affect the behavior of TO_NUMBER.
TO_NUMBER
Converts a character value with the specified format to aDECIMAL type.
Syntax
SQL
Example
SQL
5230.87

