Announcement

Collapse
No announcement yet.

sc_time_diff

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

  • sc_time_diff

    script not works, and obtain only Array not value:

    $time = sc_time_diff({start_time}, 'hh-mm-ss', {end_time}, 'hh-mm-ss');

    sc_alert($time);

  • #2
    sc_time_diff

    sc_time_diff

    script not works, and obtain only Array not value:

    $time = sc_time_diff({start_time}, 'hh-mm-ss', {end_time}, 'hh-mm-ss');

    sc_alert($time);

    Comment


    • #3
      According to the documentation:
      "The result will be returned in an array, with the dimensions [0], [1] and [2] containing hours, minutes and seconds, respectively."

      You need to do something like:
      $hours = $time[0];
      sc_alert($hours);

      jsb

      Comment


      • #4
        ok..works..thanks...

        Comment


        • #5
          but if i want add minute , i try but not works , $hours = $time[0,1];

          Comment


          • #6
            $newtime = $time[0].':'.$time[1];

            jsb

            Comment


            • #7
              Originally posted by jsbinca View Post
              $newtime = $time[0].':'.$time[1];

              jsb
              It is created the time as 1:30, but now use the field int e'mi by mistake I have to use varchar field? I would then add the results

              Comment


              • #8
                Sorry, but I'm not quite sure what exactly you want to do.
                The result of the sc_time_diff() macro gives you the time difference in an array with 3 'fields', $time[0] = hours, $time[1] = minutes, $time[2] = seconds, as plain integer numbers.

                If you want to add some minutes (before showing it) you can just use
                $time[1] += 5; //this would add 5 minutes, but be advised, it does not carry over the hour at 60!

                If you want a correct time calculation you have to bring it in a time format.

                $newtime = $time[0].':',$time[1]; // As you noticed, this gives you the time in hours:minutes as a string, in order to be human readable.

                Now, if you want to add or subtract some minutes you have to convert it to a machine readable format. One solution is:

                $newtime = strtotime($newtime) + 120; //this adds 2 minutes (120 = 2 minutes x 60 seconds)

                Finally convert it back to human readable.
                $newtime = date('h:i',$newtime); // this gives you '1:32';

                The final statement would be:
                $newtime = date('h:i', strtotime($newtime) + 120);

                As I said, this is one solution, for more options please read there:
                http://php.net/manual/en/book.datetime.php

                jsb

                Comment


                • #9
                  I am new to scriptcase and have a related question.
                  I have date and time in a variable {time] stored in Date and Time (SQL DATETIME) format.
                  I need to extract hour but there is no macro similar to the sc_date_conv macro which works so well to extract month, day and year. I am trying to use sc_time_diff to calculate the difference with time = 00:00:00 to extract hour as $timearray[0] but have been unsuccessful.

                  Here is the code I have
                  $timearray = sc_time_diff("01/24/2016 00:00:00","MM/dd/yyyy HH:mm:ss",{time}, "db_format"); //I am assuming that the DATETIME format requires me to have both date and time but I have tried time only

                  {hour_int} = $timearray[0]; // hoping to have hour as an integer returned from $timearray[0]

                  Thanks for any help

                  Comment

                  Working...
                  X