Number of days between 2 dates


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.