gergy008 Posted April 21, 2011 Share Posted April 21, 2011 Hi, I managed to source this code that allows me to work out how many days until a date. However I don't know how it works so I can't change it to make it work out months. Can someone kindly help me understand it? Also this code uses the unix timestamp system. $cdate = $deadlinedate; $today = time(); $difference = $cdate - $today; if ($difference < 0) { $difference = 0; $days=floor($difference/60/60/24); All help appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/234335-working-out-months/ Share on other sites More sharing options...
kenrbnsn Posted April 21, 2011 Share Posted April 21, 2011 The Unix timestamp is the number of seconds elapsed since January 1, 1970. The time function returns that number for "right now". I assume that $deadlinedate is the number of seconds for a date in the future. To get the number of days between those two dates, you use the formula you have: 60 = number of seconds/minute, 60 = number of minutes/hour, 24 = number of hours/day. Or you could just divide by 86400 -- the number of seconds in a day. To get the number of months is harder, since the number of days/month is variable. You can get an approximate value by: <?php $months = floor($days/30); ?> or <?php $months = floor($days/31); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/234335-working-out-months/#findComment-1204442 Share on other sites More sharing options...
joel24 Posted April 21, 2011 Share Posted April 21, 2011 have a look a this post Quote Link to comment https://forums.phpfreaks.com/topic/234335-working-out-months/#findComment-1204445 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.