Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ocient.com/llms.txt

Use this file to discover all available pages before exploring further.

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

PatternDescription
Y,YYY4 digit year with comma
YYYY4 digit year
YYYLast 3 digits of a year. Values between 000-599 are assumed to be the year 2XXX and 600-999 are assumed to be the year 1XXX.
YYLast 2 digits of a year. Values between 00-69 are assumed to be the year 20XX and 70-99 are assumed to be 19XX.
YLast digit of a year. Assumed to be year 200X.
BC, bc, AD, or adAn era indicator BC or AD in upper or lower case
B.C., b.c., A.D., or a.d.An era indicator B.C. or A.D. in upper or lower case
CCCentury value 1-99. Is ignored unless YY, Y, IY, or I are set
MMMonth of the year value 01-12
MONTHUpper case English month name
MonthEnglish Month name with first letter capitalized
monthlower case English month name
RMUpper case month of year in Roman numerals
rmLower case month of year in Roman numerals
MON3 letter upper case abbreviation of an English month name
Mon3 letter abbreviation of an English month name with first letter capitalized
mon3 letter lower case abbreviation of an English month name
WWeek of month 1-5. For example: Days 15-21 are in the third week of the month.
DDDay of month 1-31
WWWeek of year 1-53
DDDDay of year 1-366
DDay of week 1-7 where Sunday is 1. This value is ignored outside of to_char.
IYYY4 digit ISO-8601 week-numbered year. See ISO week date for more details.
IYYLast 3 digits of an ISO-8601 week-numbered year. Values between 000-599 are assumed to be the year 2XXX and 600-999 are assumed to be the year 1XXX.
IYLast 2 digits of an ISO-8601 week-numbered year. Values between 00-69 are assumed to be the year 20XX and 70-99 are assumed to be 19XX.
ILast digit of an ISO-8601 week-numbered year. Assumed to be the year 200X.
IDDDDay of an ISO-8601 week-numbered year 001-371
IWWeek of an ISO-8601 week-numbered year 01-53
IDDay of an ISO-8601 week 01-07 where Monday is 1
HH or HH12Hour of day 01-12
HH24Hour of day 0-23
AM, am, PM, or pmMeridiem indicator AM or PM in upper or lower case
A.M., a.m., P.M., or p.m.Meridiem indicator A.M. or P.M. in upper or lower case
SSSSSeconds after midnight 0-86399
MIMinute of hour 0-59
SSSecond of minute 0-59
MSMilliseconds 000-999
USMicroseconds 000000-999999
NSNanoseconds 000000000-999999999
JJulian Day (days after November 24, 4714 BC at midnight)
The following modifiers can also be applied to a format pattern.

Date and Timestamp Formatting Modifiers

ModifierDescription
FMHas no effect on TO_DATE and TO_TIMESTAMP. Will not be considered a literal, but will not otherwise affect the behavior.
THUpper case ordinal number suffix. For example: 'DDTH'
thLower case ordinal number suffix. For example: 'DDth'
FXGlobal prefix. By default, TO_DATE and TO_TIMESTAMP collapse all spaces to a single space. If FX is specified, spaces are not collapses. FX must be at the beginning of the format string to be applied. For example: 'FX YYYY-MM-DD'
TMHas no effect on TO_DATE and TO_TIMESTAMP. Will not be considered a literal, but will not otherwise affect the behavior.
SPHas no effect on TO_DATE and TO_TIMESTAMP. Will not be considered a literal, but will not otherwise affect the behavior.

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
TO_TIMESTAMP(character_value, character_format)
ArgumentsData TypeDescription
character_valueCHARA string of a value to be converted to a TIMESTAMP type. The string must match the provided character_format.
character_formatCHARThe format pattern to be used to convert the character_value. See the Date and Timestamp Formatting Patterns section for more information about accepted pattern values.
Examples
SQL
SELECT TO_TIMESTAMP('2022/12/01', 'YYYY/MM/DD');
Output: 2022-12-01 00:00:00.000
SQL
SELECT TO_TIMESTAMP('2023-02-28 13:43:20.403', 'YYYY/MM/DD HH24:MI:SS');
Output: 2023-02-28 13:43:20.000

TO_DATE

Converts a character value with the specified format to a DATE type. Syntax
SQL
TO_DATE(character_value, character_format)
ArgumentsData TypeDescription
character_valueCHARA string of a value to be converted to a DATE type. The string must match the provided character_format.
character_formatCHARThe format pattern to be used to convert the character_value. See the Date and Timestamp Formatting Patterns section for more information about accepted pattern values.
Example
SQL
SELECT TO_DATE('2022/12/01', 'YYYY/MM/DD');
Output: 2022-12-01

Number Formatting Functions

Number Formatting Patterns

PatternDescription
9A digit.
0A digit. In TO_CHAR, includes leading zeros.
. or DA decimal point.
, or GA group/thousand separator.
PRNegative value in braces. For example: -1 = <1>
S or SGA + or - sign for positive or negative, respectively.
MIA - sign if the number is negative.
PLA + sign if the number is positive.
VShifts the decimal place by the number of digits after V in the format. Cannot be mixed with . or D. For example: TO_NUMBER('32', '9V99') => 0.32
RNRoman numeral. Not supported by TO_NUMBER.
EEEEExponent for scientific notation. Not supported by TO_NUMBER.
LCurrency symbol.

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
TO_NUMBER(character_value, character_format)
ArgumentsData TypeDescription
character_valueCHARA string of a value to be converted to a DECIMAL type. The string must match the provided character_format.
character_formatCHARThe format pattern to be used to convert the character_value. See the Number Formatting Patterns section for more information about accepted pattern values.
Example
SQL
SELECT TO_NUMBER('5230.87', '9999V99');
Output: 5230.87 Date and Time Functions Time Zone Functions Character and Binary Functions
Last modified on May 21, 2026