Discussion:
DB2 Datetime question
(too old to reply)
c***@hotmail.com
2007-08-27 04:25:00 UTC
Permalink
Is this sql valid in DB2?
Where insert value is a date time.

INSERT INTO TABLE1 VALUES ('27-Aug-2007 12:21:18');

If Not, Can you show me the correct sql?
I get SQLState 22007 while run this sql, which is the invalid datetime.
Mark A
2007-08-27 05:35:34 UTC
Permalink
Post by c***@hotmail.com
Is this sql valid in DB2?
Where insert value is a date time.
INSERT INTO TABLE1 VALUES ('27-Aug-2007 12:21:18');
If Not, Can you show me the correct sql?
I get SQLState 22007 while run this sql, which is the invalid datetime.
DB2 has the following date/time datatypes:

date
time
timestamp
(no date/time)

For a timestamp use this:

'2007-08-27 12:21:18.0'

You can put in up to 6 zeros, but only one is mandatory. If you select the
timestamp column from a table you can see the correct format. You can also
do this:

select current_timestamp, current_date, current_time from sysibm.sysdummy1;
Knut Stolze
2007-08-27 14:09:39 UTC
Permalink
Post by Mark A
Post by c***@hotmail.com
Is this sql valid in DB2?
Where insert value is a date time.
INSERT INTO TABLE1 VALUES ('27-Aug-2007 12:21:18');
If Not, Can you show me the correct sql?
I get SQLState 22007 while run this sql, which is the invalid datetime.
date
time
timestamp
(no date/time)
'2007-08-27 12:21:18.0'
You can put in up to 6 zeros, but only one is mandatory.
You don't have to provide fractions of a second at all. DB2 assumes .000000
as default.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Continue reading on narkive:
Loading...