RE: [PHP] Date Question
| From: | John Huggins | Date: | Thu, 08 Mar 2001 17:20:35 +0000 |
| Subject: | RE: [PHP] Date Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-43037@lists.php.net to get a copy of this message | ||
You might try converting these dates to Unix time and then compare the
numbers as integers.
Let's see, here is a function that converts the data from a MySQL date field
to a Unix timestamp...
function mysql_to_epoch ($datestr)
{
list($year,$month,$day,$hour,$minute,$second) =
split("([^0-9])",$datestr);
return date("U",mktime($hour,$minute,$second,$month,$day,$year));
}
And here is where I use it to calculate the age of the item in the database.
$epochTime = mysql_to_epoch($messageCreated);
$currentEpochTime = time();
$ageInSeconds = $currentEpochTime - $epochTime;
I hope this provides a clue for your application.
John
> -----Original Message-----
> From: Chris [mailto:php_list@ibcnetwork.net]
> Sent: Thursday, March 08, 2001 12:12 PM
> To: php
> Subject: [PHP] Date Question
>
>
> Hi,
> Since there is no Date type in php, is there a way to compare dates?
>
> Something like:
>
> if ((3/8/2001) < (3/9/2001)){
> // Date is newer
> }
>
> Thanks,
> Chris
>