Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a 1-hour expiration to the current time/date

Tags:

php

//expiration
$datetoday = date("F j, Y, G:i");

$expquery = mysql_query("SELECT a_expire FROM regform_admin WHERE status = 'Pending for payment'");
$row = mysql_fetch_array($expquery); 
$expirydate = $row['a_expire'];
echo "$datetoday";
echo "$expirydate";
if ($datetoday == $expirydate) {
    $expirequery = mysql_query("UPDATE regform_admin SET status = 'Expired' WHERE status = 'Pending'");
    $expirequery2 = mysql_query("UPDATE regform SET status = 'Expired' WHERE status = 'Pending'");
}
//end expiration

Hi, I have an expiration of reservation code here. My problem is that if a customer makes a reservation on 23:30 and the reservation will expire at 00:30 (1 hour), I made this code:

$currentdate = date("F j, Y, G:i");  
$onehour = date("G") + 1;
$expire = date("F j, Y, $onehour:i");

The $onehour must increment, but the problem is that the 23:30 reservation must expire at 24:30. But after incrementing the $onehour, the 23:30 results into 24:40. Which my program cannot read since military time of 12am is 00:00 and not 24:00. Can anyone have suggestions in my problem? Thanks. Sorry for the lazy english I was tired of thinking

like image 452
glove Avatar asked Aug 18 '11 16:08

glove


2 Answers

$expire = date("F j, Y, H:i", strtotime('+1 hour'));
like image 60
Dan Grossman Avatar answered Sep 26 '22 00:09

Dan Grossman


$expire = date("F j, Y, H:i", time()+3600); // 3600 sec in hour
like image 29
RiaD Avatar answered Sep 26 '22 00:09

RiaD