Jump to content

PHP time in the future


Pain

Recommended Posts

Hello.

 

I am trying to create time in the future.

<?php

$time_in_minutes = (round($time / 60));
$future_time = date("H:i:s",time() + 60 * $time_in_minutes);

?>

 

It all works. I get something like "15:58:28". Now if i want to insert this record into the database, which type should i pick? DATETIME or TIMESTAMP?

 

Note that i want to check whether the current time has now passed the future time.

 

Thanks:)

Link to comment
https://forums.phpfreaks.com/topic/274108-php-time-in-the-future/
Share on other sites

Why not just the DateTime class with a relative time format?

$time = new DateTime ('+1 hour');

This has the added benefit of dealing with not only midnight automatically, but also leap seconds.

 

In any case, I'd go for a TIME field for this. Since you're only storing the time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.