Adsense

Friday, April 26, 2013

How to change the date format in db2


Changing the date format in db2 can be done very easily by issuing 2 commands.
If the data base was created using territory=US , by default the date format looks like MM/DD/YYYY
You can check the format by entering the following command on db2 CLP
db2=> values current date
Output :
1
----------
06/21/2011
1 record(s) selected.

To change the date format, you have to bind the collection of db2 utility packages to use a different date format.
To change the default format to YYYY-MM-DD , which is ISO (International Standards Organization) , do the following steps:

Go to the command prompt & change directory to sqllib\bnd.
On Windows, issues the following commands
cd c:\Program Files\IBM\SQLLIB\bnd
db2 connect to database_name

->where database_name is the actual database name in your system.
db2 bind @db2ubind.lst datetime ISO blocking all grant public

After issuing the above command , the follwing message will be displayed.
LINE MESSAGES FOR db2ubind.lst
------ --------------------------------------------------------------------
SQL0061W The binder is in progress.
LINE MESSAGES FOR db2clpnc.bnd
------ --------------------------------------------------------------------
SQL0595W Isolation level "NC" has been escalated to "UR".
SQLSTATE=01526
LINE MESSAGES FOR db2arxnc.bnd
------ --------------------------------------------------------------------
SQL0595W Isolation level "NC" has been escalated to "UR".
SQLSTATE=01526
LINE MESSAGES FOR db2ubind.lst
------ --------------------------------------------------------------------
SQL0091N Binding was ended with "0" errors and "2" warnings.

Note : On Linux machine path will be /home/db2inst1/sqllib/bnd
Now, you can see date format of the data base which uses ISO date format by issuing the following command
Enter the following command on db2 CLP
db2=> values current date
Output :
1
----------
2011-06-21
1 record(s) selected.

The other formats supported are:
DEF - Date and time format associated with the territory code.
EUR - IBM standard for Europe date and time format
JIS - date and time format of the Japanese Industrial Standard
LOC - Use the date and time format in local form associated with the territory code of the database.
USA - IBM standard for U.S. date and time format

To change the date back to US format , run the following command
db2 bind @db2ubind.lst datetime USA blocking all grant public

0 comments:

Post a Comment