tags:

views:

47

answers:

2

How do you validate a date in MySQL ? In SQL Server, we have "ISDATE()" to validate whether the expression is a valid date. What function do we use in MySQL ?

A: 

Simply use date(your_date_here) and that will check if a date is valid.

EDIT:

If you really wanna have a isDate returning true or false, you can use this:

CREATE FUNCTION IsDate (sIn varchar(1024)) RETURNS INT 
BEGIN 
declare tp int; 

if (select length(date(sIn)) is null )then 
set tp = 0; 
else 
set tp = 1; 
end if; 
RETURN tp; 
END 

cheers

Marcos Placona
I think I have tried this out. What will be the return value for this function ?
Sreejesh Kumar
thanks. will try this out. Actually I was about to import data from a table in MySQL to SQL SErver 2008 through SSIS. But I cant transfer due to Dates in the table. There are some data of datetime data type, like '0001-01-10' which doesnt support in SQL Server where years in date ranges from 1753 to 9999. So how do i solve this in MySQL queries ?
Sreejesh Kumar
It returns 1 ot 0You're changing the subject slightly here. Why do you wanna move it to SQL then?
Marcos Placona
ok. I will try !
Sreejesh Kumar
Let us know the outcome
Marcos Placona
A: 

Try a solution like this one I used with Oracle to Sql Server move in SSIS. http://stackoverflow.com/questions/2231028/dealing-with-timestamp-datetime-when-copying-data-from-oracle-to-sql-server-using/2231164#2231164
From your description, Oracle and MySql appear to handle dates similarly.

William Todd Salzman