PHP Weekly (May 18, 2008)
Today, were talking about dates, specifically getting the difference between two dates.
We will be using GregorianToJD(); which converts a Gregorian date to Julian Day Count.
This is handy when you need to find out how many days have passed since a specific date or the difference in days between two dates.
Here is an example:
- dateDiff('8','25','1975','2','26','2004');
- function dateDiff($m1,$d1,$y1,$m2,$d2,$y2)
- {
- $date1 = gregoriantojd($m1,$d1,$y1);
- $date2 = gregoriantojd($m2,$d2,$y2);
- $diff = $date2 - $date1;
- echo $diff;
- }
Above is a simple function that you send in to dates and you get back the difference in days. Simple, but can be very useful.