Home » SQL & PL/SQL » SQL & PL/SQL » Date Validation
Date Validation [message #2527] Tue, 23 July 2002 20:45 Go to next message
Alvin Yap
Messages: 1
Registered: July 2002
Junior Member
Hi!
I have a html form which passes 3 values for the date, the month, date and year to my ASP form, joins them together into a mm/dd/yyyy format, which is accepted by oracle (using the to_date())

We found a bug in which when invalid dates are entered, e.g. 30th Feb or 31st september are entered, "ORA-01839: date not valid for month specified" error occurs.

Are there any methods/functions used to validate if the date entered to the system is a valid calender date?

Thank you!

Regards,
Alvin
Re: Date Validation [message #2528 is a reply to message #2527] Tue, 23 July 2002 22:02 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
A simple function can handle this for you. You can either have the function do the date conversion and return a null if the date is invalid, or the function can just return true or false to indicate a valid date.

create or replace function f_is_valid_date(
  p_month in varchar2, p_day in varchar2, p_year in varchar2)
  return date
is
begin
  return (to_date(p_month || p_day || p_year, 'mmddyyyy'));
exception
  when others then
    return (null);
end;
/


or

create or replace function f_is_valid_date(
  p_month in varchar2, p_day in varchar2, p_year in varchar2)
  return boolean
is
  v_date  date;
begin
  v_date := to_date(p_month || p_day || p_year, 'mmddyyyy');
  return (true);
exception
  when others then
    return (false);
end;
/
Previous Topic: SELECT OWN RECORDS INSTEAD OF OWNER's RECORD
Next Topic: last saturday
Goto Forum:
  


Current Time: Thu Apr 25 13:07:37 CDT 2024