scrupul0us Posted August 16, 2006 Share Posted August 16, 2006 So I've been putzing around with various scipts online to basically just tell me how many:years months weeks daysare left between now and a given dateive tried hotscripts and all that jazz but most are insanely bulky or just dont worke.g... if my event date is August 11 2007 the output should be (based on today august 16 2006):11 months 3 weeks 5 daysso far ive gotten nothing to work Quote Link to comment Share on other sites More sharing options...
paul2463 Posted August 16, 2006 Share Posted August 16, 2006 try this $until needs to be a timestamp and not a date though, see example at the end ( This is based on months only having 30 days though)[code]function formatetimestamp($until){ $now = time(); $difference = $until - $now; $months = floor($difference/2592000); $difference = $difference - ($months*2592000); $weeks = floor($difference/604800); $difference = $difference - ($weeks*604800); $days = floor($difference/86400); $difference = $difference - ($days*86400); $output = "You have to wait $months Months, $weeks Weeks, $days Days until this Day"; return $output;}//int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )echo formatetimestamp(mktime(0,0,0,12,31,2006)); //output: e.g "You have to wait 5 Months 1 Week 5 Days until this Day"[/code]hope that helps Quote Link to comment Share on other sites More sharing options...
scrupul0us Posted August 16, 2006 Author Share Posted August 16, 2006 yesi tried that from php.net but it did not work for me when i passed:mktime(0,0,0,08,11,2007)i got: 11 months 51 weeks 360 days (based on yesterdays date) Quote Link to comment Share on other sites More sharing options...
paul2463 Posted August 16, 2006 Share Posted August 16, 2006 Hi , Sorry about that maybe I should have checked it before posting it, I have modified it so it works now, here is the code, it takes a date string as the input now in the form of the example at the bottom again[code]<?PHPfunction formatetimestamp($until){ $months = 0; $weeks = 0; $days = 0; $now = strtotime("now"); $difference = $until - $now; $test = floor($difference/2592000); if($test > 0){ $months = $test; $difference = $difference - ($months*2592000); } $test = floor($difference/604800); if($test > 0){ $weeks = $test; $difference = $difference - ($weeks*604800); } $test = floor($difference/86400); if ( $test > 0) { $days = $test + 1; $difference = $difference - ($days*86400); } $output = "You have to wait $months Months, $weeks Weeks, $days Days until this Day"; return $output;}echo formatetimestamp(strtotime("31 august 2006")); ?>[/code]try it nowagain it is not extremely accurate because is predicated on all months having 30 days, to keep it simple, it gives a good idea though Quote Link to comment 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.