Date in ESQL/C
Posted in 2000
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
I have short question I want to retrieve in select statement date as a string with four digits in year eg: select some_date into :my_date from some_table where ... I have date in such format: "99-05-05" but I'd like to have "1999-05-05" What should I do? It is possible to do this automatically? I have dates like 1900 as well as 2000... Is there any variable or option responsible for that? Adam
If you are trying to convert a date column into a string variable, try the TO_CHAR built-in SQL function. For example, SELECT TO_CHAR(today, '%Y-%m-%d') FROM systables WHERE tabid = 1; will return the string "2000-07-05". Rudy Adam Gagatek wrote: > I have short question > > I want to retrieve in select statement date as a string > with four digits in year eg: > > select some_date into :my_date from some_table where ... > > I have date in such format: "99-05-05" but I'd like > to have "1999-05-05" > > What should I do? > It is possible to do this automatically? > I have dates like 1900 as well as 2000... > > Is there any variable or option responsible for that? > > Adam
Adam Gagatek wrote: > I want to retrieve in select statement date as a string > with four digits in year eg: > > select some_date into :my_date from some_table where ... > > I have date in such format: "99-05-05" but I'd like > to have "1999-05-05" > > What should I do? It is possible to do this automatically? > I have dates like 1900 as well as 2000... > > Is there any variable or option responsible for that? If you want to retrieve dates directly into strings, the DBDATE and TO_CHAR() options already suggested are your main options. If you used the following, it omits the leading zeroes, of course, besides being very ungainly. (YEAR(date) || "-" || MONTH(date) || "-" || DAY(date)) Alternatively, use the rfmtdate() function or its various friends; see the ESQL/C Programmers Manual. And look at SQLCMD to see some code that allows you to decode DBDATE into what those functions need (http://www.iiug.org). -- Yours, Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h> Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN "I don't suffer from insanity; I enjoy every minute of it!"