Posted By

klovera on 01/21/11


Tagged

php days calculate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

diskostu
buddharage


Number of days between 2 dates


 / Published in: PHP
 

URL: http://www.klovera.com/php-subtract-dates/

// example $from = '2011-1-6'; $to = '2011-1-8'; dateDiff($from,$to); // returns 2

  1. function dateDiff($beginDate, $endDate) {
  2. $fromDate = date('Y-n-j',strtotime($beginDate));
  3. $toDate = date('Y-n-j',strtotime($endDate));
  4. $date_parts1=explode('-', $beginDate);
  5. $date_parts2=explode('-', $endDate);
  6. $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
  7. $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
  8. return $end_date - $start_date;
  9. }

Report this snippet  

You need to login to post a comment.