NEED TO CHECK FORMAT TO 'YYYY-MM-DD'
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


NEED TO CHECK FORMAT TO 'YYYY-MM-DD' Expand / Collapse
Author
Message
Posted 3/31/2006 12:16:11 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 6/18/2007 5:02:00 PM
Posts: 18, Visits: 1
Hi,
I have a column which is of type varchar(20) and which holds date value. Now i need to verify whether the data in the column is having correct date format.
Date format should be YYYY-MM-DD.

Thanks,
rlaskar
Post #3891
Posted 3/31/2006 12:37:14 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 6/9/2008 2:55:55 PM
Posts: 185, Visits: 2
There are two ways to do this that I know of. One is to write a UDF. There is currently a UDF available with the Oracle UDF's called "toDate" that converts a character column to a date. It produces an error if the date cannot convert. However, you can easily modify it to return a NULL if the column does not contain a valid date which is what I did with it.

Secondly, you could join to the SYS_CALENDAR table as follows:

sel CALENDAR_DATE
FROM your_table yt,
LEFT OUTER JOIN SYS_CALENDAR.CALENDAR CAL
ON (CALENDAR_DATE (FORMAT 'YYYY-MM-DD') (CHAR(10))) = yt.mydate;

If the date is valid, you will get the result in a DATE data type. If the date is invalid, you will get a NULL back.

Good luck.

Barry

Post #3893
Posted 3/31/2006 3:24:16 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 6/18/2007 5:02:00 PM
Posts: 18, Visits: 1
Thanks. But it's still not working for me.

The column that i have is of type varchar(20) and it have value as "ABCDEFGH".
If I ran the above query it returns me all the rows from the table.
Say Field ABC of type varchar(20) is having values like
2006/01/01
2006_01_01
abcdehgjih
2001-01-01
01-02-2006 and so on.

I want to find the invalid date not the one that is valid. So my SQL should return only abcdehgjih as invalid date.
Post #3894
Posted 4/3/2006 12:39:26 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 6/9/2008 2:55:55 PM
Posts: 185, Visits: 2
Modify the query to the following:

sel yt.mydate
FROM your_table yt,
LEFT OUTER JOIN SYS_CALENDAR.CALENDAR CAL
ON (CALENDAR_DATE (FORMAT 'YYYY-MM-DD') (CHAR(10))) = yt.mydate
WHERE CALENDAR_DATE IS NULL;

Note that this is only considering the date to be valid if it's in the YYYY-MM-DD format. In order to check the other formats, you would have to do additional left outer joins to the date table with the various formats.

Thanks,
Barry
Post #3910
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 1 ( 1 guest, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 3:33am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.016. 7 queries. Compression Disabled.