Home Page for the TeradataForum
 
https:

Archives of the TeradataForum

Message Posted: Fri, 06 Apr 2007 @ 15:48:41 GMT


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


Subj:   Re: Specify input format for date
 
From:   Nimmala, Meher Tej

Hi,

Here is an example with startdate column.

     CASE STARTDATE
     WHEN '00/00/0000' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '00-00-0000' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '00000000' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '0000/00/00' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '0000-00-00' THEN CAST('9999-12-31' AS DATE FORMAT 'YYYY-MM-DD')
     WHEN '12/31/9999' THEN CAST(STARTDATE AS DATE FORMAT 'MM/DD/YYYY')
     WHEN '12-31-9999' THEN CAST(STARTDATE AS DATE FORMAT 'MM-DD-YYYY')
     WHEN '12319999' THEN CAST(STARTDATE AS DATE FORMAT 'MMDDYYYY')
     WHEN '99991231' THEN CAST(STARTDATE AS DATE FORMAT 'YYYYMMDD')
     WHEN '9999/12/31' THEN CAST(STARTDATE AS DATE FORMAT 'YYYY/MM/DD')
     WHEN '9999-12-31' THEN CAST(STARTDATE AS DATE FORMAT 'YYYY-MM-DD')
     ELSE
     CASE SUBSTR(STARTDATE,3,1)
     WHEN '/' THEN CAST(STARTDATE AS DATE FORMAT 'MM/DD/YYYY')
     WHEN '-' THEN CAST(STARTDATE AS DATE FORMAT 'MM-DD-YYYY')
     ELSE
     CASE CHARACTER_LENGTH(TRIM(STARTDATE))
     WHEN 10 THEN CAST(STARTDATE AS DATE FORMAT 'YYYY-MM-DD')
     WHEN 8 THEN CAST(STARTDATE AS DATE FORMAT 'YYYYMMDD')
     ELSE CAST((TRIM(STARTDATE )) AS DATE FORMAT 'YYYYMMDD')
     END
     END
     END STARTDATE

Hope this helps.

Thanks

Meher Nimmala
Teradata Certified Master
NCR- Teradata



     
  <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: 28 Jun 2020