Hi :
I'm trying to take a form field and verify weather the user entered a valid date. I'm the form I have the field defaulted to the current date but the user can enter another date when they submit the form it saves all this information to the database.
any help here would be appretiated.
Thanks in advance.
verifying date help??
Moderator: General Moderators
Substr
If you get the date from one field I guess you could run the result trough substr and sort out day, month and year, then validate each of those.
Of course you can do more checking, you can put the months in groups of 30 and 31 days (february alone of course) and check the day up against the month if it's 31 etc....
Hope this helped
Rincewind_the_Wizzard
Code: Select all
$date = $_GETї'date'];
// in my country we write a date dd.mm.yy or dd.mm.yyyy
$day = substr($date,0,2); //extract the first two digits ie. the day
$month = substr($date,3,5); //extract the digits from (after) 3 to (including) 5 ie. the month
$year = substr($date,6,10); //extract the digits from (after) 6 to (including) 10 ie. the year
if($day < 32 AND $day > 0 AND $month < 13 AND $month >0 AND $year < 2003 AND $year > 1970 ) // I don't know your criteria here,just an example...
return true;
else
return false;Hope this helped
Rincewind_the_Wizzard
checkdate()
You can do this, but there are some pitfalls:
Checkdate takes 3 integers as input in the order month, day, year.
It will return true for 4 4 32000, tough this will not be a good date to work further on, it will accept any value for year between 0 and 32767 and I guess you want more precision than that.
I suggest you first check year the way I showed you, then run checkdate to check if the date is valid for that year.
Think this should do the trick.
Rincewind_the_Wizzard
Checkdate takes 3 integers as input in the order month, day, year.
It will return true for 4 4 32000, tough this will not be a good date to work further on, it will accept any value for year between 0 and 32767 and I guess you want more precision than that.
I suggest you first check year the way I showed you, then run checkdate to check if the date is valid for that year.
Code: Select all
if ($year < 2003 AND $year > 1950)
checkdate($month, $day, $year);Rincewind_the_Wizzard