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 > Convert field but retain format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-03, 09:58
RudiVdm RudiVdm is offline
Registered User
 
Join Date: Sep 2003
Posts: 17
Convert field but retain format

Hi,

My problem is as follows :

On my database I have a view that is currently casting a date as char(10). The reason for this so that i can see the dates in SQL server (0001/01/01). Now what seems to be happening, is that on the cast, my date format is getting messed around, ie : from yyyy-mm-dd i am now only getting yy-mm-dd in the text field.

Using SQL server, i could overcome this problem by replacing the CAST with a CONVERT, but I don't know how to do this in DB2.

Any ideas?
Reply With Quote
  #2 (permalink)  
Old 10-08-03, 12:08
RudiVdm RudiVdm is offline
Registered User
 
Join Date: Sep 2003
Posts: 17
In other words, how do i cast "0001/01/01" (date) as "0001/01/01" (char) ?
Currently after casting the yyyy becomes yy ...
Reply With Quote
  #3 (permalink)  
Old 10-08-03, 13:36
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
use the function VARCHAR_FORMAT
Reply With Quote
  #4 (permalink)  
Old 10-08-03, 13:38
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Instead of CAST try using the CHAR function

CHAR(HIRE_DATE, ISO)

The ISO date is in format 'YYYY-MM-DD'

If you want all dates and times to appear in the ISO format without using the CHAR function, I believe that there is a DB2 instance setting to accomplish this.
Reply With Quote
  #5 (permalink)  
Old 10-08-03, 14:20
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Actually, I am not sure which format you wanted. Here are the DB2 formats:

ISO yyyy-mm-dd 1991-10-27
USA mm/dd/yyyy 10/27/1991
EUR dd.mm.yyyy 27.10.1991
JIS yyyy-mm-dd 1991-10-27
Reply With Quote
  #6 (permalink)  
Old 10-09-03, 08:43
RudiVdm RudiVdm is offline
Registered User
 
Join Date: Sep 2003
Posts: 17
Smile Voila!

Thanks guys, worked brilliantly. Also saved me alot of headline headache.
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