Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 06 Jun 2002 @ 20:01:28 GMT


     
  <Prev Next>  
<<First
<Prev
Next> Last>>  


Subj:   Date to text conversion
 
From:   Nick Druga

This works, but there must be an easier way to convert a date field to a character string with a format of yyyymmdd. 1/1/2002 must convert to 20020101. Any suggestions?

Code:

select                           cast(extract(  year from datefield) as char(4))   ||
substr(                    '00'||cast(extract( month from datefield) as char(2)),
   char(TRIM(TRAILING FROM '00'||cast(extract( month from datefield) as char(2))))
-1,2)
   ||
substr(                    '00'||cast(extract(   day from datefield) as char(2)),
   char(TRIM(TRAILING FROM '00'||cast(extract(   day from datefield) as char(2))))
-1,2) as yyyymmdd
from table1
;


     
  <Prev Next>  
<<First
<Prev
Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023