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
https://forums.phpfreaks.com/topic/234335-working-out-months/
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
https://forums.phpfreaks.com/topic/234335-working-out-months/#findComment-1204442
Share on other sites

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.