SkyRanger Posted November 1, 2008 Share Posted November 1, 2008 I am trying to convert the output to month days: $sql = "SELECT * FROM ".$prefix."_holiday_countdown"; $result = $db->sql_query($sql); while ( $row = $db->sql_fetchrow($result) ) { $hmonth = $row['hmonth']; $hday = $row['hday']; $hyear = $row['hyear']; $holiday = $row['hholiday']; } $target = mktime(0, 0, 0, $hmonth, $hday, $hyear) ; $today = time () ; $difference =($target-$today) ; $days =(int) ($difference/86400) ; $content = " $days till ".$holiday; I am trying to figure out how to get it to convert to ? months ? days till $holiday Link to comment https://forums.phpfreaks.com/topic/130961-solved-convert-to-monthdays/ Share on other sites More sharing options...
Jeremysr Posted November 1, 2008 Share Posted November 1, 2008 Assuming that a "month" is 30 days, you could do this: $difference = ($target - $today); $months = $difference / 60 / 60 / 24 / 30; $days = ($days / 60 / 60 / 24) % 30; $content = "$months months, $days days until ".$holiday; Link to comment https://forums.phpfreaks.com/topic/130961-solved-convert-to-monthdays/#findComment-679840 Share on other sites More sharing options...
SkyRanger Posted November 1, 2008 Author Share Posted November 1, 2008 Almost but I am getting the output of: 1.7996091821 months, 0 days until Christmas Link to comment https://forums.phpfreaks.com/topic/130961-solved-convert-to-monthdays/#findComment-679842 Share on other sites More sharing options...
zenag Posted November 1, 2008 Share Posted November 1, 2008 use floor.. $months = floor($difference / 60 / 60 / 24 / 30); Link to comment https://forums.phpfreaks.com/topic/130961-solved-convert-to-monthdays/#findComment-679844 Share on other sites More sharing options...
Jeremysr Posted November 1, 2008 Share Posted November 1, 2008 Whoops, should've tested my code. This is tested and works: $difference = ($target - $today); $months = floor($difference / 60 / 60 / 24 / 30); $days = ($difference / 60 / 60 / 24) % 30; $content = "$months months, $days days until"; Link to comment https://forums.phpfreaks.com/topic/130961-solved-convert-to-monthdays/#findComment-679845 Share on other sites More sharing options...
SkyRanger Posted November 1, 2008 Author Share Posted November 1, 2008 Awesome guys, thank you, never used floor before that is probably when I could not figure it out. Learn something new every day. Link to comment https://forums.phpfreaks.com/topic/130961-solved-convert-to-monthdays/#findComment-679848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.