I am trying to figure out what is the best way to
- Grab the current date/time (is
date('Y-m-d H:i:s')
best?) - Grab the db date from SQL
- Check if the current date (#1) is between the date pulled from the DB and 5hours after it
I'm a newbie at php.
I am trying to figure out what is the best way to
date('Y-m-d H:i:s')
best?)I'm a newbie at php.
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';
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
}