XXX Chats

Sex chat no registration java powered

Time between dates dating

Both functions support many options to modify the default behavior.

$date1 = "2007-03-24"; $date2 = "2009-06-26"; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); printf("%d years, %d months, %d days\n", $years, $months, $days); Edit: Obviously the preferred way of doing this is like described by jurka below.

My code is generally only recommended if you don't have PHP 5.3 or better.

In this article, I emphasized two little-known options: the 'CONTINUOUS' option in INTCK and the 'SAME' option in INTNX.

By using these options, you can to compute the number of anniversaries between dates and the most recent anniversary.

* * @param Date Interval $interval The interval * * @return string Formatted interval string.

*/ function format_interval(Date Interval $interval) /** * Format an interval to show all existing components.The resulting Year and Day variables contain the same information as is displayed in the Wikipedia table.In summary, the INTCK and INTNX functions are essential for computing intervals between dates.*/ function format_interval(Date Interval $interval) $first_date = new Date Time("2012-11-30 "); $second_date = new Date Time("2012-12-21 "); $difference = $first_date-$date1 = "2008-11-01 "; $date2 = "2009-12-04 "; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); $hours = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); $minuts = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); $seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60)); printf("%d years, %d months, %d days, %d hours, %d minuts\n, %d seconds\n", $years, $months, $days, $hours, $minuts, $seconds); It doesn't matter which date is earlier or later when you pass in the date parameters.The function uses the PHP ABS() absolute value to always return a postive number as the number of days between the two dates.You can use the 'CONTINUOUS' option for the INTCK function and the 'SAME' option for the INTNX function, as follows: !If you request the number of days between two dates, the INTCK function includes leap days in the result.Several people in the comments have pointed out that the code above is only an approximation.I still believe that for most purposes that's fine, since the usage of a range is more to provide a sense of how much time has passed or remains rather than to provide precision - if you want to do that, just output the date.The data was taken from a Wikipedia table (shown below) that shows the number of years and days between events.This article shows how you can use the INTCK and INTNX functions in SAS to compute the time between events in this format.

Comments Time between dates dating