Page 1 of 1

if compare statement

Posted: Fri Mar 21, 2014 2:50 pm
by ali90
Please tell me if following answer is correct

Question : User has filled a form where he had to put date of birth , need to code a couple of php statement which should do verification of date of birth , if the date of birth of birth is in future date from today then an error should come up .

answer:
$dob = $day . $month . $year; // this will combine day , month and year as they were taken as different values

if $now < $dob; // this is if statement which matches NOW time with input dob

echo " Please enter correct date of birth";

Re: if compare statement

Posted: Fri Mar 21, 2014 2:55 pm
by Celauran
$now isn't defined.

11032014 > 10102222

Re: if compare statement

Posted: Sat Mar 22, 2014 8:52 am
by ali90
If i have to define current time using now variable I could put

$now = "2014-03-22"

and then do the comparison , would this be correct ?

Re: if compare statement

Posted: Sat Mar 22, 2014 8:56 am
by Celauran
So long as you remember to order them both the same, that should work fine. Rather than hardcoding a date as $now, though, wouldn't it make more sense to use, say, date('Y-m-d')?