ballhogjoni Posted December 15, 2008 Share Posted December 15, 2008 How can I find out how many have gone by this year? for example, I need to know how many days have gone by since 01/01/2008 to 07/22/2008. Anyone have any good ideas? thx. Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/ Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 You could do a loop like so: <?php $bContinue = true; $sDate = strtodate("01/01/2008"); $eDate = strtodate("07/22/2008"); $i=0; while ($eDate > $sDate) { $sDate = $sDate + (60*60*24); // one date $i++; } echo $i . " days have passed."; There may be a better way, but that should work. Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/#findComment-715833 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 Not sure if you can use arithmetic like this but: $sub = strtotime(07/22/2008) - strtotime(01/01/2008); //get timestamp (seconds) $sub = ($sub/3600) / 24; // get days seconds / 60*60*24 = 1 day echo int_val($sub); //round to nearest integer Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/#findComment-715835 Share on other sites More sharing options...
flyhoney Posted December 15, 2008 Share Posted December 15, 2008 <?php $day1 = date('z', strtotime('01/01/2008')); $day2 = date('z', strtotime('07/22/2008')); echo "Days between: " . ($day1 - $day2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/#findComment-715847 Share on other sites More sharing options...
flyhoney Posted December 15, 2008 Share Posted December 15, 2008 Or this maybe: <?php $diff = strtotime('01/01/2008') - strtotime('07/22/2008'); $days = $diff / 3600; echo "Days between: " . $diff; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/#findComment-715848 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 Wouldn't: $days = $diff / 3600; give you hours? 60(secs)*60(minutes) = hours Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/#findComment-715862 Share on other sites More sharing options...
flyhoney Posted December 15, 2008 Share Posted December 15, 2008 Wouldn't: $days = $diff / 3600; give you hours? 60(secs)*60(minutes) = hours Definitely, screwed up my mathz. $days = $diff / (60 * 60 * 24); Quote Link to comment https://forums.phpfreaks.com/topic/137062-solved-date-question/#findComment-715868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.