Jump to content

Working out months.


gergy008

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.