|
|
Archives of the TeradataForum
Message Posted: Thu, 06 Jun 2002 @ 20:01:28 GMT
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
;
| |