tags:

views:

79

answers:

2

I am trying to figure out what is the best way to

  1. Grab the current date/time (is date('Y-m-d H:i:s') best?)
  2. Grab the db date from SQL
  3. Check if the current date (#1) is between the date pulled from the DB and 5hours after it

I'm a newbie at php.

+2  A: 

Pull the date you wanted from MySQL

  SELECT myDateCol FROM myTable WHERE ...

Convert this into a UNIX timestamp

$db_timestamp = strtotime($db_row['myDateCol']);

Check if the date from the DB is within the last 5 hours

if ($db_timestamp >= strtotime('-5 hours')) echo 'DB date is within last 5 hours';
pix0r
A: 

Use PHP's DateTime class:

$start = new DateTime("2009/09/17 18:52:31");
//Your SQL request should set this

$end = date_add($start,new DateInterval("PT5H"))

$now = new DateTime();

if($start<$now && $now<$end)
{
//etc
}
Eric
He said five hours, not five minutes.
Robert L
Actually, the M stands for months. Well spotted though. I wasn't paying intention. Copy and paste finger strikes again...
Eric