Announcement

Collapse
No announcement yet.

[SOLVED] Time Difference - Urgent Help Please

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [SOLVED] Time Difference - Urgent Help Please

    Hi,

    I have 2 fields in the database, TimeIn and TimeOut, I need to display the difference between both on the Grid, how can I do that and in which Event should be set?

    Thank you

  • #2
    Event onRecord:

    PHP Code:
    $time_in_sec strtotime({TimeIn});
    $time_out_sec strtotime({TimeOut});

    // next day?
    if ($time_out_sec $time_in_sec)
        {       
        
    // add one day (86.400 seconds)
        
    $time_out_sec += 86400;
        }

    $diff_min = (($time_out_sec $time_in_sec) / 60);

    {
    your_difference_field} = $diff_min
    HTH.
    Last edited by RHS; 09-11-2013, 04:37 AM.
    Best regards: - Reinhard -

    I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

    Comment


    • #3
      Originally posted by RHS View Post
      Event onRecord:

      PHP Code:
      $time_in_sec strtotime({TimeIn});
      $time_out_sec strtotime({TimeOut});

      // next day?
      if ($time_out_sec $time_in_sec)
          {       
          
      // add one day (86.400 seconds)
          
      $time_out_sec += 86400;
          }

      $diff_min = (($time_out_sec $time_in_sec) / 60);

      {
      your_difference_field} = $diff_min
      HTH.
      Hi, Thank you, I am still having big difference:

      Time In
      11:00:00
      Time Out
      12:25:00
      Time Consumed
      85:00:00
      With your formula, I am getting 85:00:00 while it should be 01:25:00
      Can you help please?

      Thanks

      Comment


      • #4
        The result is correct, the difference is 85 minutes... (60+25).

        $diff_min = (($time_out_sec - $time_in_sec) / 60);


        So you need to do a bit of work to get the notation as you want it...
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Originally posted by aducom View Post
          The result is correct, the difference is 85 minutes... (60+25).
          Puh ... ;-)

          PHP Code:
          $h floor($diff_min 60);
          $m = ($diff_min 60);
          $s 0;
          $diff_time sprintf("%02d:%02d:%02d"$h$m$s); 
          Best regards: - Reinhard -

          I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

          Comment


          • #6
            Am I a bit too hard Reinhard? ;-)
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development
            www.scriptcase.eu / www.scriptcase.nl

            Comment


            • #7
              Puh = ... happiness had again ... ;-)
              Best regards: - Reinhard -

              I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

              Comment


              • #8
                Originally posted by RHS View Post
                Puh ... ;-)

                PHP Code:
                $h floor($diff_min 60);
                $m = ($diff_min 60);
                $s 0;
                $diff_time sprintf("%02d:%02d:%02d"$h$m$s); 
                RHS, you're super.. many thanks

                Comment

                Working...
                X