pocobueno1388 Posted March 11, 2007 Share Posted March 11, 2007 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 More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 $test_time, $today and $time_diff are all in seconds, so you can add any numbers of seconds to any of those depending on what you are trying to achieve Link to comment https://forums.phpfreaks.com/topic/42260-calculating-seconds/#findComment-205008 Share on other sites More sharing options...
pocobueno1388 Posted March 11, 2007 Author Share Posted March 11, 2007 I want it to display: 2 days 4 hours 45 minutes 29 secs left I'm not exactly sure where you would pull the seconds from...I guess it would be counting the number of seconds left until the $diff_mins changed. Link to comment https://forums.phpfreaks.com/topic/42260-calculating-seconds/#findComment-205009 Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 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 More sharing options...
pocobueno1388 Posted March 11, 2007 Author Share Posted March 11, 2007 Perfect =D Thank you so much. Link to comment https://forums.phpfreaks.com/topic/42260-calculating-seconds/#findComment-205018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.