RE: [PHP] PHP & MySQL DATE comparison
| From: | Ryan Schefke | Date: | Wed, 16 Jun 2004 16:58:08 +0000 |
| Subject: | RE: [PHP] PHP & MySQL DATE comparison | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188412@lists.php.net to get a copy of this message | ||
Hi All,
Answering my own question here, maybe this will help others out:
I found a nifty function below that will return seconds from Unix epoch to a
mysql value in the datetime format. I'll just compare this to the php
function time(). Let me know if anyone has a better solution.
<?
############
# C2001 CodeHeadz.net
# Function is released under the GPL and is free as long as
# this header remains intact
#############
function datetime_to_epoch($date) {
$break = explode(" ", $date);
$datebreak = explode("-", $break[0]);
$time = explode(":", $break[1]);
$epoch = date("U",
mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0])
);
$datetime = date("Y-m-d H:i:s",
mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0])
);
}
?>
-----Original Message-----
From: Ryan Schefke [mailto:ryan@triomfgroup.com]
Sent: Wednesday, June 16, 2004 12:43 PM
To: Php-General-Help
Subject: [PHP] PHP & MySQL DATE comparison
Hello,
I'm pulling a date in the "datetime" format via a MySQL query. Using PHP I
would like to check if that date is prior to today's date. Can someone
please help with this quick question.
Thanks,
Ryan