How to check if a datetime from mysql is the same Date as another?
I am trying to use this function:
these variables are stored in datetime format of mysql.
var1:2012-02-01 01:39:32
var2:2012-02-02 01:47:11
PHP Code:
if (date('Ymd', $var1) == date('Ymd', $var2)
{
//True
}
Why does this output true every time?
Any other suggestions on how to do this? Please keep in mind I'm limited to doing this in PHP on this page without using any database. And I'm looking only for the same date not a 24Hour difference, however I don't care about differences in time zones as long as both variables reflect the same timezone.
Re: How to check if a datetime from mysql is the same Date as another?
It is always true because it does not compare the time part, only the date part. You need to use different pattern that includes the time part also.
Or better you can compare the milliseconds from the two dates.
Re: How to check if a datetime from mysql is the same Date as another?
I was going to suggest you should ask this question on a PHP forum, but then I would have to not answer it :-/
PHP: date - Manual
... says the argument is a Unix timestamp - not a MySQL datetime. What do you get if you echo the expressions either side of the '=='?