Delimiter //
/**
function cash_IsDate
Check if value could be cast to Date

accepted value for parameter format :
	- 101, 1 : ISO, witout delimiter, with or witout century (ex 20013112)
	- 102, 2 : french or italian, with delimiter, with or witout century(ex 31/12/2001)
	- 103, 3 : UK, with delimiter, with or witout century (ex 12/31/2001)
	- 104, 4 : US, with delimiter, with or witout century (ex 2001/31/12)

**/

drop function if exists CASH_ISDATE //

-- create function CASH_ISDATE(value varchar(255), format )
create function CASH_ISDATE(value varchar(255), format Int, datePartDelimiter Varchar(1) )
--	returns int
	returns varchar(50)
Begin
	Declare
			validFormat,
			dVal, mVal, yVal
		int;
	-- Declare datePartDelimiter  varchar(2);
	Declare part1, part2, part3 varchar(4);
	Declare formatMatch  varchar(50);


	call CASH_DATEPART(value, format, datePartDelimiter, dval, mval, yVal, validFormat);
	if validFormat<1 Then
		return validFormat;
	End if;

	if dval < 1 Then
		return -1;
	Elseif mVal < 1 Then
		return -2;
	Elseif mVal > 12 Then
		return -2;
	Elseif yVal < 0 Then
		return -3;
--	Elseif yVal < 1970 Then
--		return -3;
--	ElseIf yVal>2049 Then
--		return -4;
	elseif mval = 2 Then
		if(dVal<29) Then
			return 1;
		elseif dVal = 29 and mod(yVal, 4 ) = 0 Then
			return 1;
		else
			return -6;
		End If;
	Elseif mVal in (2,4,6,9,11) Then
		if dVal > 30 Then
			return -6;
		End If;
	Else
		if dVal > 31 Then
			return -6;
		End If;
	End If;
	return 1;

End //

Delimiter ;