Jump to content

Time Only Conversion


phpretard

Recommended Posts

I need to compare current time to data based time.

 

Time in the database is in this format > 00:00:00

Easy enough. 

 

>>>>What I need is to convert "00:00:00" format into "time();" format<<<<

 

The opposite is below...it's all I could come up with so far.

 

<?
$gettime = time();
$displayTime = date('H:i:s', time());
echo $displayTime;
?>

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/215118-time-only-conversion/
Share on other sites

I need to compare current time to data based time.

 

Time in the database is in this format > 00:00:00

Easy enough. 

 

>>>>What I need is to convert "00:00:00" format into "time();" format<<<<

 

The opposite is below...it's all I could come up with so far.

 

<?
$gettime = time();
$displayTime = date('H:i:s', time());
echo $displayTime;
?>

 

Thank you.

 

time() format is a timestamp in seconds so you can build a timestamp that is the specified time for today and compare those:

 

$databaseTime = strtotime('06:30:00');  // or whatever, just use strtotime() on it
$displayTime = time();

if($databaseTime > $displayTime) {
   echo 'db time is greater';
elseif($databaseTime < $displayTime) {
   echo 'current time is greater';
} else {
   echo 'the times are equal';
}

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.