glove
glove

Reputation: 217

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

//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

Upvotes: 5

Views: 19646

Answers (5)

Elton da Costa
Elton da Costa

Reputation: 1277

try it:

$t = strtotime('2015-10-27 11:19:04');
$d = date('Y-m-d H:i:s', $t );
echo $d . "<br/>";
$t = $t + 3600;
$d = date('Y-m-d H:i:s', $t );
echo $d . "<br/>";

Upvotes: 0

Pierre-Luc
Pierre-Luc

Reputation: 39

Why don't you just check if the current hour is 23 ? Something like (I'm not sure about the PHP syntax of ternary operator though) :

$onehour = date("G) > 22 ? 0 : date("G) + 1;

Then you also want to change the current day, and check if you change year.

Upvotes: 0

RiaD
RiaD

Reputation: 47658

$expire = date("F j, Y, H:i", time()+3600); // 3600 sec in hour

Upvotes: 2

Dan Grossman
Dan Grossman

Reputation: 52372

$expire = date("F j, Y, H:i", strtotime('+1 hour'));

Upvotes: 12

Alex Howansky
Alex Howansky

Reputation: 53636

$one_hour_from_now = strtotime('+1 hour');

So, all you need is:

$expire = date('F j, Y, G:i', strtotime('+1 hour'));

Upvotes: 0

Related Questions