[PHP] PHP MySQL DATE comparison

2004-06-16 Thread Ryan Schefke
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



RE: [PHP] PHP MySQL DATE comparison

2004-06-16 Thread Ryan Schefke

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:[EMAIL PROTECTED] 
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php