Calculate duration between two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • archulu
    New Member
    • Mar 2007
    • 34

    Calculate duration between two dates

    hai
    this is archulu. i am new to domapi.now my problem is in my project i am taken 2 domapi datepickers. what i am want Calculate duration between two dates which i am selected in that datepicker.

    ex: two dates are selected from domapi are 29-04-2007 01-05-2007
    i want result is duration between is 3days.i want result plz help to me
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    1.convert the two strings to two Date objects

    2. subtract one from the other

    3. divide the result by 86400000

    4. round the result with Math.floor for whole days

    Comment

    • anejamanish
      New Member
      • Apr 2007
      • 3

      #3
      Originally posted by archulu
      hai
      this is archulu. i am new to domapi.now my problem is in my project i am taken 2 domapi datepickers. what i am want Calculate duration between two dates which i am selected in that datepicker.

      ex: two dates are selected from domapi are 29-04-2007 01-05-2007
      i want result is duration between is 3days.i want result plz help to me

      // calc to seconds
      $datefrom = strtotime(29-04-2007, 0);
      $dateto = strtotime(01-05-2007, 0);
      // calc difference in seconds
      $difference = $dateto - $datefrom;

      if($difference> 86400)
      {
      // reformat to days
      $datediff = floor($differen ce / 86400);
      $unit='days';
      echo $datediff.$unit ;
      }

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        javascript time stamps and differences are measured in microseconds

        Comment

        Working...