Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple String To Date Conversion In DB2

Status
Not open for further replies.

mark1110

Programmer
Apr 20, 2005
85
US
I am trying frantically to convert a string to a date in DB2. I have a query something like this:

SELECT * FROM AddressBook WHERE BirthDate = '01/01/06'

What can I use to convert the '01/01/06' string to a date? Birthdate is a date field.

Thanks,

Mark

 
Mark,
Try changing the string to '01.01.2006' or '01/01/2006'. I think that it may depend on your installation's default settings, but I have found that the first one tends to work in most places.

Regards,

Marc
 
db2 "values date(char(left('01/03/2006',6)||'20'||right('01/03/2006',2)))"

This sql inserts the century int your date, the result appears to be a VARCHAR, so it is cast th CHAR before th data function.
 
Mark,
I've just re-read my post from earlier and realised that I had mis-typed. It's meant to read the CCYY first, so your example would be '2006-01-01' or .2006.01.01'.

Apologies.

Let us know how you get on.

Marc
 
If I could type.......

or '2006.01.01'

the previous post should read.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top