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
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';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.