开发者

Validate Date at MySQL

开发者 https://www.devze.com 2022-12-22 09:34 出处:网络
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 ?Simply use date(your_date

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 ?


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


Try a solution like this one I used with Oracle to Sql Server move in SSIS. Dealing with Timestamp/Datetime when copying data from Oracle to SQL Server using SSIS
From your description, Oracle and MySql appear to handle dates similarly.

0

精彩评论

暂无评论...
验证码 换一张
取 消