If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Any clever way to convertChar to Date?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-11-06, 21:25
victorlung victorlung is offline
Registered User
 
Join Date: Mar 2006
Posts: 2
Any clever way to convertChar to Date?

Hi All,

I would like to convert a date in char type with the format 'dd/mm/yyyy' (eg. 30/01/2006) into date datatype before inserting into the table.

instead of substring the char into day, month and year, Is there any faster way to do that?

Thank you very much.
Reply With Quote
  #2 (permalink)  
Old 07-12-06, 01:36
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
to date

can this not be used ?
TO_DATE--(--string-expression--,format-string--)----
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #3 (permalink)  
Old 07-13-06, 02:12
crabbie_upk crabbie_upk is offline
Registered User
 
Join Date: Jul 2005
Posts: 2
Date to Char

Hi,

You can convert date to character using te function to_char.

Example: to_char(sysdate, 'DD-MON-YYYY') will return the date in ther format DD-MON-YYYY like 01-JAN-2006.

rgds,
Uday
Reply With Quote
  #4 (permalink)  
Old 07-13-06, 09:50
willyunger willyunger is offline
Registered User
 
Join Date: Dec 2004
Posts: 7
Date Conversion

Hi, Victor,

I believe this would solve your little puzzle:

db2 values date ( replace ('30/01/2006','/', '.'))

1
----------
01/30/2006

1 record(s) selected.

Of course, you could have your application substitute the slashes by periods and submit the string to the DATE function directly!

Hope this helps,

Willy



Quote:
Originally Posted by victorlung
Hi All,

I would like to convert a date in char type with the format 'dd/mm/yyyy' (eg. 30/01/2006) into date datatype before inserting into the table.

instead of substring the char into day, month and year, Is there any faster way to do that?

Thank you very much.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On