Date Validation [message #221413] |
Mon, 26 February 2007 10:50 |
hariyadav
Messages: 12 Registered: February 2007 Location: hyderabad
|
Junior Member |
|
|
Hi all,
Good morning.
I have a problem while get the day name from a given date.
For my function,I am sending the date as parameter as FEB 28, 2003, it reuturns as FRI which is correct.
For the next case I am sending FEB 29, 2003 as a parameter it is not valid date.
Before send above date, I need to validate date. whether that date is exist or not.
Can any one please help me how validate whether the given is valid date or not (FEB 29, 2003).
Thanks in advance.
Hari Yadav.G
|
|
|
|
Re: Date Validation [message #221446 is a reply to message #221413] |
Mon, 26 February 2007 16:47 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
CREATE OR REPLACE FUNCTION chk_date(date_str,date_format)
RETURN BOOLEAN
IS
v_year number;
BEGIN
SELECT TO_CHAR (date_str,date_format)
INTO v_year
FROM DUAL;
RETURN TRUE;
exception when others then
RETURN FALSE;
END chk_date;
|
|
|
Re: Date Validation [message #221560 is a reply to message #221422] |
Tue, 27 February 2007 07:58 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
vamshi wrote on Mon, 26 February 2007 14:04 | Hello Friend,
Just check out this function and let me know.
CREATE OR REPLACE FUNCTION chk_year
RETURN BOOLEAN
IS
v_year number;
BEGIN
SELECT TO_CHAR (SYSDATE, 'YYYY')
INTO v_year
FROM DUAL;
IF MOD (v_year, 4) = 0 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END chk_year;
|
I am wondering how this answer has anything to do with the question.
|
|
|
Re: Date Validation [message #221564 is a reply to message #221560] |
Tue, 27 February 2007 08:11 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Well, it's an answer to the special case that the OP posted, of a Leap year date in a non leap year. @vamshi has decided that this must be the only possible problem that the OP could be having, and solved that, rather than actually answer the OPs question.
Takes all sorts, I guess.
|
|
|
|
Re: Date Validation [message #222036 is a reply to message #222028] |
Thu, 01 March 2007 09:03 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Or, if you want something that works MUCH quicker, and is usable in SQL without resorting to CASE statements and allows you to use your default format, try this:CREATE OR REPLACE FUNCTION valid_date(date_str VARCHAR2
,date_format VARCHAR2 default null)
RETURN varchar2 IS
v_date date;
BEGIN
if date_format is not null then
v_date := to_date(date_str,date_format);
else
v_date := to_date(date_str);
end if;
return 'Y';
EXCEPTION
WHEN OTHERS THEN
RETURN 'N';
END valid_date;
You can use this either in the SELECT clause or the WHERE clause
|
|
|