0

I prefer to calculate date time in Codeigniter as below description

I select date from database with two different duration

  1. From_date = 2014-11-30,
  2. To_date = 2014-12-03,

I want to get result as below.

duration = from_date-To_date

duration = ?

<?php 
    $exp = date("y-m-d",strtotime($invoice->fto));
    $now = date("y-m-d",time());
    $diffday = $now-$exp;
    echo $diffday;
?>

As above code I get only 0

Cootel Kh
  • 97
  • 1
  • 3
  • 15
  • 3
    possible duplicate of [How to calculate the difference between two dates using PHP?](http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – vaso123 Nov 28 '14 at 12:29
  • [Google](https://www.google.co.in/?gfe_rd=cr&ei=92p4VNqpDoLW8ge8jYCQCA&gws_rd=ssl#q=How+to+calculate+duration+of+two+different+of+two+date+in+php) –  Nov 28 '14 at 12:31

1 Answers1

0

CodeIgniter has a helper function, that will do this for you, within the date helper. Called "timespan"

https://ellislab.com/codeigniter/user-guide/helpers/date_helper.html

echo timespan($exp, $now);
Craig
  • 1,823
  • 1
  • 11
  • 12