Link to home
Start Free TrialLog in
Avatar of willsherwood
willsherwood

asked on

PHP: compare (<) two times given in MySQL text format

I have echoed the two times (as an example) of a comparison i'm trying to do:

2011-02-22 16:42:05  <  2011-02-22 16:38:11

I've tried:  comparing the two text strings directly(!);   strcmp();   and  strtotime < strtotime

how is the best way to do this successfully?   (the strlen is always the same)

thanks
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of willsherwood
willsherwood

ASKER

thanks, i retried, more confidently this time, and it worked.
(something else was amiss and i was blaming it on the  <  comparison!)

appreciated
$date1='2011-02-22 16:42:05';
$date2='2011-02-22 16:38:11';

if(strtotime($date1)  <  strtotime($date2))
{
    echo "ok";
}