Page 1 of 1

please help with date comparison

Posted: Fri Oct 08, 2010 3:53 pm
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?

Re: please help with date comparison

Posted: Fri Oct 08, 2010 4:06 pm
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

Re: please help with date comparison

Posted: Fri Oct 08, 2010 4:15 pm
by Obadiah
as i posted in the previous code thats comented out..the (==) comparison didnt work either...but im open for more ideas!

Re: please help with date comparison

Posted: Fri Oct 08, 2010 4:31 pm
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.

Re: please help with date comparison

Posted: Fri Oct 08, 2010 4:37 pm
by Obadiah
its working now...thanks bro!