Jump to content

Date Greater Then Or Equal To


Ustag

Recommended Posts

Hi, so if today is 27/10-11 and I have added the date 28/10-11, 29/10-11 and 30/10-11 in the database and decided to show the date 1 day before the date. Then it would show tomorrows date which is 28/10-11. So I make an if statement: //$row2["m"] = month number//$row2["d"] = day number//$row2["days"] = number of days before the date to show it//$row2["y"] = last 2 numbers in the year if(date('j/n-y', mktime(0, 0, 0, $row2["m"], $row2["d"]-$row2["days"], $row2["y"])) >= date('j/n-y', mktime(0, 0, 0, date('n'), date('j'), date('y'))))){echo "tomorrow";} So I say, If the date in the database is in 1 days from today I will echo "tomorrow". but the result is:28/10-1129/10-1130/10-11 so the 28/10-11 is correct but the other two dates are set to show 0 days before the date so it should not show. Does this mean that my if statement is wrong? The dates in the if statement does show correct dates so I wonder if this is not the way to do "greater then or equal to" when dealing with dates. I hope you udnerstand what I mean, Thank you.

Link to comment
Share on other sites

You're using greater than or equal, so it would match everything later, not just one day. The real problem is you're trying to compare strings like "28/10-11" and "29/10-11" using alphabetic comparison. It's going to consider 30/1-1 to also be greater than 29/12-12, because it's an alpabetic comparison. You should be comparing the output of mktime, not converting that number to a text string.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...