Jump to content

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

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;

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";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.