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:

  1. dateDiff('8','25','1975','2','26','2004');
  2.  
  3. function dateDiff($m1,$d1,$y1,$m2,$d2,$y2)
  4. {
  5. $date1 = gregoriantojd($m1,$d1,$y1);
  6. $date2 = gregoriantojd($m2,$d2,$y2);
  7.  
  8. $diff = $date2 - $date1;
  9.  
  10. echo $diff;
  11. }

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.

This entry was posted on Saturday, May 17th, 2008 at 9:18 am and is filed under Web Design. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

Leave a Reply