Informix and DATE types — a fun (complicated) topic. Actually, it is fairly simple from within the Informix world; it is when other systems get involved with different views on how things should be done that it gets tricky.
If things are set up correctly (e.g. as in my environment), you could write in the Informix world:
INSERT INTO tablename(daterequested) VALUES('2013-07-03');
And you could substitute double quotes for single quotes because Informix is lax about the difference unless you hold its hand to the fire and say "I want to be shouted at when I use double quotes".
More elaborately, you could also write:
INSERT INTO tablename(daterequested) VALUES(DATETIME(2013-07-03) YEAR TO DAY);
This will work because (a) the formats for DATETIME are fixed in ISO 8601 (Date/Time Formats) or ISO 9075 (SQL) format and (b) Informix will convert from DATETIME YEAR TO DAY to DATE without any qualms. This is reliable, and doesn't rely on any environment variable settings or other complications, unlike the first version.
You could also reliably write:
INSERT INTO tablename(daterequested) VALUES(MDY(7, 3, 2013));
This uses a function MDY to convert the three integers to a DATE; the order of the arguments is (mnemonically) month, day, year. This is reliable because it doesn't depend on environment variables.
The first notation (using string '2013-07-03'
) relies on environment variables. The classic variable is $DBDATE
; I run with DBDATE=y4md-
set in the environment, so strings like '2013-07-03'
are interpreted as in ISO 9075. However, the default value for DBDATE is effectively DBDATE=mdy4/
for US-style dates. However again, there are other variables, such as CLIENT_LOCALE, DB_LOCALE, and GL_DATE that all want to get in on the game. I use DBDATE because it gets top priority (and has done since the beginning of time), but the newer (other) variables have their merits. You can also experiment with:
INSERT INTO tablename(daterequested) VALUES(DATE('07/03/2013'))
Note the quotes and the parentheses. The string is interpreted according to the environment variables. Don't try DATE(2013-07-03)
because that is equivalent to DATE(2003)
(2013 minus 7 is 2006; 2006 - 3 is 2003), and because day 1 was 1900-01-01, day 2003 was 1905-06-16, a Monday.
The SQL standard provides for DATE '2013-03-07'
but Informix does not support that parentheses-less notation.
You'll need to stick the SQL Server notations back into the SQL syntax, but the MDY and DATETIME methods will work, and you can finagle the DATE methods into working if you're willing to work with the environment variables or modify the format of the date string to match the expected behaviour.