Oracle To_date Utc

Posted on  by admin

Question: I have a date field in an Oracle table and I want to insert a new record. I'm trying to insert a date with a time component into this field, but I'm having some problems.

This Oracle tutorial explains how to use the Oracle / PLSQL FROMTZ function with syntax and examples. The Oracle / PLSQL FROMTZ function converts a TIMESTAMP value (given a TIME ZONE) to a TIMESTAMP WITH TIME ZONE value. Oracle TODATE The Oracle TODATE function converts a date literal to a DATE value.

How can I insert this value into the table.

For example, the value is '3-may-03 21:02:44'

Answer: To insert a date/time value into the Oracle table, you'll need to use the TO_DATE function. The TO_DATE function allows you to define the format of the date/time value.

For example, we could insert the '3-may-03 21:02:44' value as follows:

Learn more about the TO_DATE function.

The Oracle TO_DATE() function converts a date literal to a DATE value.


The following illustrates the syntax of the Oracle TO_DATE()function:


The TO_DATE() function accepts three arguments:

1) string

is a string value which is converted to a DATE value. It can be a value of any data type CHAR, VARCHAR2, NCHAR, or NVARCHAR2.

2) format

is the date and time format for the string.


The format argument is optional. If you omit the format, the string must be in the standard date format which is DD-MON-YY e.g., 31-DEC-2000

Noted that if format is J, which is for Julian, then the string must be an integer.

Oracle To_date Utc

For the detailed information on how to construct the format, check it out the Oracle date format.

3) nls_language

is an expression that specifies the language for day and month names in the string. This nls_language argument has the following form:

Oracle To_date Utc Download

This ls_language argument is optional. If you omit it, the TO_DATE() function will use the default language for your session.

Return value

The TO_DATE() function returns a DATE value which is corresponding to the input string.


A) Basic TO_DATE() function example

To convert a string to date, you use the Oracle date format elements e.g., YYYY for the 4-digit year, MM for the 2-digit month, etc.

Suppose, you have the following date literal:

To convert this string to a DATE value, first, you must construct the date format model for it. In this case, 5 is represented by DD, Jan is represented by Mon, and 2017 is represented by YYYY that results in the following format:

Second, you pass both arguments, date literal and format model, to the TO_DATE() function as shown below:

The following illustrates the output:

Oracle Get Utc Date

If you fail to construct the format, the TO_DATE() function will issue a respective error.

For example, if you miss one character Y in the date format model above:

The TO_DATE() function issued the following error:

Oracle to_date utc

B) Use TO_DATE() function to insert data into a table

The following statement creates a table named members:

Oracle Date To Utc

The following statement inserts a new row into the members table.

In this example, because Feb 01 2017 is not Oracle standard date format, you have to use the TO_DATE() function to convert it to a DATE value before storing in the table.

Here is another example of inserting a date value a DATE column using the TO_DATE() function for formatting.

You can check whether the data was actually inserted by using the following query:

Oracle Cast Date To Utc

In this tutorial, you have learned how to use the TO_DATE() function to convert a string into a DATE value.