Skip to main content

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_DATE and TO_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 and TO_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 a TIMESTAMP type. Syntax
SQL
Examples
SQL
Output: 2022-12-01 00:00:00.000
SQL
Output: 2023-02-28 13:43:20.000

TO_DATE

Converts a character value with the specified format to a DATE type. Syntax
SQL
Example
SQL
Output: 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 a DECIMAL type. Syntax
SQL
Example
SQL
Output: 5230.87 Date and Time Functions Time Zone Functions Character and Binary Functions
Last modified on May 20, 2026