Re: Calculating the difference between two dates

From: Date: Mon, 24 Mar 2003 09:31:47 +0000
Subject: Re: Calculating the difference between two dates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140817@lists.php.net to get a copy of this message
Hello, First you need to convert dates in timestamp: int mktime ( int hour, int minute, int second, int month, int day, int year [, int is_dst]) or strtotime('YYYY-MM-DD'); (year-month-date; 4 digit year; month and date need to be with leading zero) Then you can use function like DateDiff('yyyy', $date1, $date2); /*** * Interval: - yyyy Year - q Quarter - m Month - y Day of year - d Day - w Weekday - ww Week of year - h Hour - n Minute - s Second */ function DateDiff($interval, $date1, $date2) { // get the number of seconds between the two dates $timeDifference = $date2 - $date1; $res = 0; switch ($interval) { case 'yyyy': $diff = 0; break; case 'q': $diff = 0; break; case 'm': $diff = 0; break; case 'y': $diff = 0; break; case 'd': $diff = bcdiv($timeDifference, 86400, 0); break; case 'w': $diff = bcdiv($timeDifference, 604800, 0); break; case 'ww': $diff = 0; break; case 'h': $diff = bcdiv($timeDifference, 3600, 0); break; case 'n': $diff = bcdiv($timeDifference, 60, 0); break; case 's': $diff = $timeDifference; break; default: $diff = 0; } $res = $diff; return $res; } ________________________ Best regards, Nenad Djordjevic mailto:nenad@diyomisoft.com Diyomi Soft http://www.diyomisoft.com/ Tuesday, March 24, 1998, 2:44:12 AM, you wrote: B2> Does any one know how to calculate the difference between two dates. I need B2> to find out the age of a user to make sure they are over the age of 13. I B2> have searched for hours on this and found nothing that will help. B2> TIA

« previous php.general (#140817) next »