if compare statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ali90
Forum Newbie
Posts: 9
Joined: Sun Mar 16, 2014 11:03 am

if compare statement

Post 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";
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if compare statement

Post by Celauran »

$now isn't defined.

11032014 > 10102222
ali90
Forum Newbie
Posts: 9
Joined: Sun Mar 16, 2014 11:03 am

Re: if compare statement

Post 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 ?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: if compare statement

Post 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')?
Post Reply