0

I have from my mysql database:

$event_date -> (mysql query get database from events) 2013-10-09

In a variable I have

$var_date = "2013-10-09"

if ($event_date == $var_date) {
bla bla (but this doesn't work)
}

I remember having this problem with another website but I don't remember. The data query from the database is not equal to a normal variable even if it contains the same thing. How can I make it to like convert to the same format?

Thank you world.

EDIT: When I echo them, they are exactly the same.

4

2 回答 2

2
$var_date = "2013-10-09";

if (trim($event_date) == trim($var_date)) {

}
于 2013-10-08T23:22:37.500 回答
0

这是我用来比较日期的函数,因为它们可以有多种不同的格式,例如年份第一年或最后一年或两位数年份。对于相同的日期/时间,它返回 0,如果 $a 小于 $b,则返回 -1,如果 $b 小于 $a,则返回 1。

function compareDates($a, $b) {
  if(!is_int($a) && !ctype_digit($a)) {
    $a = strtotime($a);
  }
  if(!is_int($b) && !ctype_digit($b)) {
    $b = strtotime($b);
  }
  if($a > $b) {
    return 1;
  }
  if($a < $b) {
    return -1;
  }
  return 0;
}
于 2013-10-08T23:21:29.653 回答