please help with date comparison

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
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

please help with date comparison

Post by Obadiah »

Im trying to do a date comparison and I am not having any success...the statement returns false :banghead:

Code: Select all

$time = time();
	$MyMonth = "October";
	$DMonth = date(F);
	
	if ($MyMonth = $Dmonth){                                                   //if ($MyMonth == $Dmonth) does not work either
	echo "yes it matches up";
	echo date("F" ,$time);	
	}
	else
	echo "no luck bro!";
	echo date("F" ,$time);
can someone tell me what im doing wrong?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: please help with date comparison

Post by twinedev »

Well, there are several issues with the code you posted, but the first thing to check would be this line:

Code: Select all

if ($MyMonth = $Dmonth){
to be

Code: Select all

if ($MyMonth == $Dmonth){
Your line assigns $myMonth to be equal to $Dmonth, the second line actually does a comparison.

-Greg
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: please help with date comparison

Post by Obadiah »

as i posted in the previous code thats comented out..the (==) comparison didnt work either...but im open for more ideas!
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: please help with date comparison

Post by twinedev »

ahh missed that (the code section doesn't show a horizonal scroll bar on here...)

Then the next to check would be that you are doing

Code: Select all

$DMonth = date(F);
instead of

Code: Select all

$DMonth = date('F');
See if that helps.
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Re: please help with date comparison

Post by Obadiah »

its working now...thanks bro!
Post Reply