Question

In SQL+, I am trying to insert a date with the year, month, day, day of the week, hour, minute, and second. Everything went as expected except for the day of the week. The original insert statement excluded the day of the week and ran perfectly

insert into auctions 
values (To_Date('AUGUST 12, 2014 11:01:02','MONTH DD, YYYY HH:MI:SS'));

however, when I attempt to include the day of the week I get an error

insert into auctions 
values (To_Date('TUE AUGUST 12, 2014 11:01:02','WTXT MONTH DD, YYYY HH:MI:SS'));

ORA-01820: format code cannot appear in date input format

Obviously I'm doing something wrong, probably the syntax of WTXT. The goal is to have the day of the week in three letter abbreviated form. What is the problem?

Was it helpful?

Solution

You need DY to represent the short day name for insert:

insert into auctions 
values (To_Date('TUE AUGUST 12, 2014 11:01:02','DY MONTH DD, YYYY HH24:MI:SS'));

The interpretation is subject to NLS settings, which may or may not be an issue for you.

The datetime format model elements are listed in the documentation. WTXT is a new on on me; I think it's complaining about the W and not looking any further, as week number is only valid in to_char().

You probably also want to be using HH24 rather than the 12-hour-clock HH, since you don't have an am/pm marker.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top