Jump to content

[SOLVED] Convert to month/days


SkyRanger

Recommended Posts

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

Whoops, should've tested my code. :PThis 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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.