DBA > Interview Resource

DB2's Dates questions and answers

Part:   1  2  3  4  5  6 

(Continued from previous part...)

Q: I want to enter date in format mm-dd-yyyy hh:mm:Ss in DB2. How can I do that?

A: Well, first of all, in DB2 the combination of date and time is known as a TIMESTAMP data type, so you will need to use TIMESTAMP as the data type instead of DATE (which is just the date with no time component). Other DBMSs use the DATE data type to store both date and time data, but not DB2.

     YYYY is year
     MM is month
     DD is day
     HH is hour
     MM is minutes
     SS is seconds and
     mmmmmm is microseconds

That is the only acceptable format of DB2 timestamp data.

Q: I want to fetch a date column with the 'DD-MMM-YYYY' format. Can I do it in a single query? I tried to run the following SQL, but got an error:

     SELECT  CHAR(T1.COL_DT ,'DD-MMM-YYYY'),
     FROM      TABLE1 T1;         

Any ideas?

A: You are not using the CHAR function correctly. When using CHAR to convert a date column into a character representation, the second parameter can only be one of the following: ISO, USA, EUR, JIS, or LOCAL. Consult Table 1 for the format to which each of these corresponds.

To return the data in the format you are requesting, DD-MMM-YYYY, you will need to install a local date format routine. Get in touch with your system programmer to discuss whether this is feasible and how to do it.

(Continued on next part...)

Part:   1  2  3  4  5  6