Am I getting "Invalid month in date" trying to run this?
I am trying to run the following db command for Informix:
delete from table1
where u_id in (select u_id
from table2
where c_id in (select c_id
from ptable
where name = 'Smith'
and dob = '29-08-1946'));
I am passing this as a string to db.ExecuteNonQuery method in MS Data Application block and getting the above error?
source to share
To get the date format '29 -08-1946 'to work, you will need the DBDATE environment variable to be set to a value such as "DMY4-" (or "DMY4 /"). These are the UK standard choices (I've used them for years, I now exclusively use "Y4MD-" which is both ISO 8601: 2004 (date formats) and ISO 9075 (SQL), except when debugging another environment) ... There are other environment variables that can affect date formatting - there are actually quite a few of them - but DBDATE takes precedence over others, so this is a big sledgehammer that fixes the problem.
One problem is that your plain string notations are not portable between US and UK (and ISO) DBDATE settings. If you have a choice, the MDY () function is the neutral constructor for dates:
WHERE dob = MDY(8,29,1946)
This works regardless of the DBDATE setting. Perhaps you can also use TO_DATE ():
SELECT TO_DATE('29-08-1946', '%d-%m-%Y') FROM dual;
Generated for me 1946-08-29 00: 00: 00.00000 - the function generates a DATETIME YEAR TO FRACTION (5) value, but they are reliably converted to DATE values ββin Informix.
You can also use the DATE () function or an explicit DATE cast (either CAST ('29 -08-1946 'AS DATE) or '29 -08-1946' :: DATE), but both are tailored to the whim of the users' language ...
source to share