I have the date in is this format:
June 22, 2012
Using PHP’s date function I am getting the date like so:
date("F j, Y")
Using an if statement I compare the two hoping to eliminate all of those dates which have already passed:
if(date("F j, Y") > $date)
However, it works but leaves all but one date:
February 14, 2012
Can someone explain why or tell me a better way to do this?
date() returns a string, so in your case its only returns strings that are greater than the literal string “June 22, 2012”. Try using strtotime() on your date() call, e.g
This will take the time string returned by date() and convert it to unix timestamp, which you can use to compare dates.