比较PHP中的服务器日志日期

I'm looking to write a simple program that will tell me the last time a search engine visited any page on my site by looking at the server logs.

For example I may have:

$date1 = 27/Jan/2013:19:17:12 -0700
$date2 = 27/Feb/2013:19:17:12 - 0700

I want to know that the last time was $date2 - how do I make PHP understand the date format? Do I first need to convert that into a format that PHP understands?

Thanks in advance for any help.

Craig

You can use strtotime() and compare timestamps

$date1 = '27/Jan/2013:19:17:12 - 0700';
$date2 = '27/Feb/2013:19:17:12 - 0700';
if(strtotime($date1) > strtotime($date2))
    echo $date1;
else
    echo $date2;

// outputs 27/Feb/2013:19:17:12 - 0700

strtotime() will do your purpose .. It will convert the date in string to timestamp and then uou can do the comparison.

<?php

$date1 = '27/Jan/2013:19:17:12 - 0700';
$date2 = '27/Feb/2013:19:17:12 - 0700';
if(strtotime($date1) > strtotime($date2))
 echo "$date1 is after $date2";
else
 echo "$date2 is after $date1";