Jump to content

Calculating Seconds


pocobueno1388

Recommended Posts

Okay, my other post about this was getting all confusing so I am going to start a new clean one...because it kinda changed into a different issue.

 

On my last post kenrbnsn gave me the following code that works perfectly for what I wanted:

 

<?php

$test_time = strtotime('2007-03-17 16:08');
$today = time();

$time_diff = $test_time - $today;
$diff_days = floor($time_diff / 86400);
$diff_hours = floor($time_diff / 3600) - ($diff_days * 24);
$diff_mins = floor($time_diff % 3600)/60;

echo sprintf("<br>%d days %2d hours %2d minutes left<br>",$diff_days, $diff_hours,$diff_mins);

?>

 

This code takes the DATETIME format stored in $test_time and gets exactly how long it will take to reach the current time from that date/time, then prints to the screen something like this:

 

2 days 4 hours 45 minutes left

 

Now I just want to add seconds to that...but I can't figure out what formula I would use from the above code to get the seconds =/ Any help would be greatly appreciated =] Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/42260-calculating-seconds/
Share on other sites

Ah!

 

<?php

$test_time = strtotime('2007-03-17 16:08');
$today = time();

$time_diff = $test_time - $today;
$diff_days = floor($time_diff / 86400);
$diff_hours = floor($time_diff / 3600) - ($diff_days * 24);
$diff_mins = floor($time_diff % 3600)/60;
$diff_secs = ($time_diff % 3600)%60; 

echo sprintf("<br>%d days %2d hours %2d minutes %2d seconds left<br>",$diff_days, $diff_hours,$diff_mins, $diff_secs);

?>

Link to comment
https://forums.phpfreaks.com/topic/42260-calculating-seconds/#findComment-205015
Share on other sites

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.