DB2 always stores the date in the same internal format. The way it is
displayed depends on the terrritory code of the client that submits the
SQL Select, but it can be overriden by using the CHAR funciton in the
select statement.
select current_date from sysibm.sysdummy 1
01/12/2007
select CHAR(current_da te, ISO) from sysibm.sysdummy 1
2007-01-12
thanks for your answer.
I agree but 2 questions:
- what is the internal format? I guess it is yyyymmdd
- how would you do the insert (SQL INSERT) to use the internal format
instead of the local format date? Is there a universal way to do an
insert with a DATE field?
Because when I do this:
select * from MYTABLE where DAT_SES = '20070115'
I get this error message:
General SQL error.
[IBM][CLI Driver][DB2/NT] SQL0180N "The syntax of the representation in
the form of chain of a value date/time is incorrect." SQLSTATE=22007
(I have translated from french, I hope this is correct. Not sure about
the word "chain" maybe STRING is a better translation).
Anyway I need to do this:
select * from MYTABLE where DAT_SES = '01/15/2007'
because, the server has the US format (mm/dd/yyyy).
I am running this query from a DB2 client from a workstation. This
workstation has the french configuration.
So the result is "15/01/2007" (french format is dd/mm/yyyy).
So, to conclude, the server format needs to be used (US forma in my
example), not the internal one nor the client one.
And the result (the display) is the local format (french format in my
configuration) .
The thing is that I do not know the server format. I mean not always.
So I don't see a solution. I don't see how to do my INSERT.
I undertsand how I can display the DATE field witht the CHAR function,
but I don't see a way to do an INSERT if I do not know the server
format which is required..
Could you help me?
Rod