<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script to get the time difference in UNIX Shell in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327449#M873718</link>
    <description>test.sh&lt;BR /&gt;-----------------------------------&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;h1=`echo $1 | cut -c1-2`   # Get Start Hour&lt;BR /&gt;m1=`echo $1 | cut -c3-4`   # Get Start Minute&lt;BR /&gt;s1=`echo $1 | cut -c5-6`   # Get Start Second&lt;BR /&gt;h2=`echo $2 | cut -c1-2`   # Get Stop Hour&lt;BR /&gt;m2=`echo $2 | cut -c3-4`   # Get Stop Minute&lt;BR /&gt;s2=`echo $2 | cut -c5-6`   # Get Stop Second&lt;BR /&gt;s3=`expr $s2 - $s1`         &lt;BR /&gt;if [ $s3 -lt 0 ]&lt;BR /&gt; then&lt;BR /&gt;  s3=`expr $s3 + 60`&lt;BR /&gt;  m1=`expr $m1 + 1`&lt;BR /&gt;fi&lt;BR /&gt;m3=`expr $m2 - $m1`&lt;BR /&gt;if [ $m3 -lt 0 ]&lt;BR /&gt; then&lt;BR /&gt;  m3=`expr $m3 + 60`&lt;BR /&gt;  h1=`expr $h1 + 1`&lt;BR /&gt;fi&lt;BR /&gt;h3=`expr $h2 - $h1`&lt;BR /&gt;if [ $h3 -lt 0 ]&lt;BR /&gt; then&lt;BR /&gt; h3=`expr $h3 + 24`&lt;BR /&gt;fi&lt;BR /&gt;for number in $h3 $m3 $s3&lt;BR /&gt; do&lt;BR /&gt; if [ $number -lt 10 ]&lt;BR /&gt;  then&lt;BR /&gt;   echo -n "0$number " &lt;BR /&gt;  else&lt;BR /&gt;   echo -n "$number "  &lt;BR /&gt; fi&lt;BR /&gt;done&lt;BR /&gt;echo ""&lt;BR /&gt;-----------------------------------&lt;BR /&gt;./test.sh 122000 164000&lt;BR /&gt;04 20 00 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Sergejs&lt;BR /&gt;</description>
    <pubDate>Fri, 09 Jul 2004 10:05:06 GMT</pubDate>
    <dc:creator>Sergejs Svitnevs</dc:creator>
    <dc:date>2004-07-09T10:05:06Z</dc:date>
    <item>
      <title>Script to get the time difference in UNIX Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327447#M873716</link>
      <description>Can someone send me a script through which I can calculate the time difference.&lt;BR /&gt;&lt;BR /&gt;For example&lt;BR /&gt;&lt;BR /&gt;begin_time=12,20,00&lt;BR /&gt;&lt;BR /&gt;end_time=16,40,00&lt;BR /&gt;&lt;BR /&gt;time_diff = ${end_time} - ${begin_time}&lt;BR /&gt;&lt;BR /&gt;The result should be 04,20,00&lt;BR /&gt;&lt;BR /&gt;Thank You,&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jul 2004 09:05:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327447#M873716</guid>
      <dc:creator>Suman_7</dc:creator>
      <dc:date>2004-07-09T09:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get the time difference in UNIX Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327448#M873717</link>
      <description>Serach the forum for date hammer.&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Fri, 09 Jul 2004 09:07:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327448#M873717</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2004-07-09T09:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get the time difference in UNIX Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327449#M873718</link>
      <description>test.sh&lt;BR /&gt;-----------------------------------&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;h1=`echo $1 | cut -c1-2`   # Get Start Hour&lt;BR /&gt;m1=`echo $1 | cut -c3-4`   # Get Start Minute&lt;BR /&gt;s1=`echo $1 | cut -c5-6`   # Get Start Second&lt;BR /&gt;h2=`echo $2 | cut -c1-2`   # Get Stop Hour&lt;BR /&gt;m2=`echo $2 | cut -c3-4`   # Get Stop Minute&lt;BR /&gt;s2=`echo $2 | cut -c5-6`   # Get Stop Second&lt;BR /&gt;s3=`expr $s2 - $s1`         &lt;BR /&gt;if [ $s3 -lt 0 ]&lt;BR /&gt; then&lt;BR /&gt;  s3=`expr $s3 + 60`&lt;BR /&gt;  m1=`expr $m1 + 1`&lt;BR /&gt;fi&lt;BR /&gt;m3=`expr $m2 - $m1`&lt;BR /&gt;if [ $m3 -lt 0 ]&lt;BR /&gt; then&lt;BR /&gt;  m3=`expr $m3 + 60`&lt;BR /&gt;  h1=`expr $h1 + 1`&lt;BR /&gt;fi&lt;BR /&gt;h3=`expr $h2 - $h1`&lt;BR /&gt;if [ $h3 -lt 0 ]&lt;BR /&gt; then&lt;BR /&gt; h3=`expr $h3 + 24`&lt;BR /&gt;fi&lt;BR /&gt;for number in $h3 $m3 $s3&lt;BR /&gt; do&lt;BR /&gt; if [ $number -lt 10 ]&lt;BR /&gt;  then&lt;BR /&gt;   echo -n "0$number " &lt;BR /&gt;  else&lt;BR /&gt;   echo -n "$number "  &lt;BR /&gt; fi&lt;BR /&gt;done&lt;BR /&gt;echo ""&lt;BR /&gt;-----------------------------------&lt;BR /&gt;./test.sh 122000 164000&lt;BR /&gt;04 20 00 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Sergejs&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jul 2004 10:05:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327449#M873718</guid>
      <dc:creator>Sergejs Svitnevs</dc:creator>
      <dc:date>2004-07-09T10:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get the time difference in UNIX Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327450#M873719</link>
      <description>The key to what you are trying to do is converting to seconds and do all the calculations and then converting back to HHMMSS. This sounds like the job for functions to me. You also need to consider the case of end_time &amp;lt; begin_time because you passed midnite.&lt;BR /&gt;&lt;BR /&gt;This should do it but it does assume that the maximum wrap is 1 day.&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;to_seconds()&lt;BR /&gt;{&lt;BR /&gt;  typeset T=${1}&lt;BR /&gt;  shift&lt;BR /&gt;  typeset -i10 HR=0&lt;BR /&gt;  typeset -i10 MIN=0&lt;BR /&gt;  typeset -i10 SEC=0&lt;BR /&gt;  typeset -i10 SECONDS=0&lt;BR /&gt;  echo "${T}" | awk -F ',' '{print $1,$2,$3}' | read HR MIN SEC&lt;BR /&gt;  typeset -i10 STAT=${?}&lt;BR /&gt;  SECONDS=$(( (${HR} * 3600) + (${MIN} * 60) + ${SEC} ))&lt;BR /&gt;  echo ${SECONDS}&lt;BR /&gt;  return ${STAT}&lt;BR /&gt;} # to_seconds&lt;BR /&gt;&lt;BR /&gt;to_hhmmss()&lt;BR /&gt;{&lt;BR /&gt;  typeset -i10 SECONDS=${1}&lt;BR /&gt;  shift&lt;BR /&gt;  typeset -i10 HR=0&lt;BR /&gt;  typeset -i10 MIN=0&lt;BR /&gt;  typeset -i10 SEC=0&lt;BR /&gt;  HR=$((${SECONDS} / 3600))&lt;BR /&gt;  MIN=$(( (${SECONDS} % 3600) / 60 ))&lt;BR /&gt;  SEC=$(( ${SECONDS} % 60 ))&lt;BR /&gt;  printf "%02d,%02d,%02d\n" ${HR} ${MIN} ${SEC}&lt;BR /&gt;  return 0&lt;BR /&gt;} # to_hhmmss&lt;BR /&gt;&lt;BR /&gt;begin_time="12,20,00"&lt;BR /&gt;end_time="16,40,00"&lt;BR /&gt;&lt;BR /&gt;begin_seconds=$(to_seconds ${begin_time})&lt;BR /&gt;end_seconds=$(to_seconds ${end_time})&lt;BR /&gt;&lt;BR /&gt;typeset -i10 DIFF=$((${end_seconds} - ${begin_seconds}))&lt;BR /&gt;if [[ ${DIFF} -lt 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    ((DIFF += 86400))&lt;BR /&gt;  fi&lt;BR /&gt;echo "Diff: ${DIFF}"&lt;BR /&gt;&lt;BR /&gt;TIMEDIFF=$(to_hhmmss ${DIFF})&lt;BR /&gt;echo "Diff: ${TIMEDIFF}"&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jul 2004 10:11:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327450#M873719</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-07-09T10:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script to get the time difference in UNIX Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327451#M873720</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; We can do it with a simple script as,&lt;BR /&gt;# cat forum.ksh&lt;BR /&gt;set -x&lt;BR /&gt;&lt;BR /&gt;# Calculate the time which the child process consumed for the Network authentication to SUT&lt;BR /&gt;time_cal()&lt;BR /&gt;{&lt;BR /&gt;    time1=$1&lt;BR /&gt;    time2=$2&lt;BR /&gt;    diff=0&lt;BR /&gt;&lt;BR /&gt;    hour1=$(($(echo $time1 | cut -d , -f 1)*3600))&lt;BR /&gt;    min1=$(($(echo $time1 | cut -d , -f 2)*60))&lt;BR /&gt;    sec1=$(echo $time1 | cut -d , -f 3)&lt;BR /&gt;&lt;BR /&gt;    hour2=$(($(echo $time2 | cut -d , -f 1)*3600))&lt;BR /&gt;    min2=$(($(echo $time2 | cut -d , -f 2)*60))&lt;BR /&gt;    sec2=$(echo $time2 | cut -d , -f 3)&lt;BR /&gt;&lt;BR /&gt;    # Assign the difference in seconds to a variable&lt;BR /&gt;    diff=$(($hour2+$min2+$sec2-$hour1-$min1-$sec1))&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;begin_time=$1&lt;BR /&gt;end_time=$2&lt;BR /&gt;&lt;BR /&gt;time_cal $2 $1&lt;BR /&gt;&lt;BR /&gt;result=$diff&lt;BR /&gt;hr=$(($result/3600))&lt;BR /&gt;div1=$(($result%3600))&lt;BR /&gt;min=$(($div1/60))&lt;BR /&gt;sec=$(($div1%60))&lt;BR /&gt;&lt;BR /&gt;hours=$hr&lt;BR /&gt;[[ $hr -lt 10 ]] &amp;amp;&amp;amp; hours="0$hr"&lt;BR /&gt;&lt;BR /&gt;mins=$min&lt;BR /&gt;[[ $min -lt 10 ]] &amp;amp;&amp;amp; mins="0$min"&lt;BR /&gt;&lt;BR /&gt;secs=$sec&lt;BR /&gt;[[ $sec -lt 10 ]] &amp;amp;&amp;amp; secs="0$sec"&lt;BR /&gt;&lt;BR /&gt;echo $hours,$mins,$secs&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar.</description>
      <pubDate>Mon, 12 Jul 2004 00:48:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-get-the-time-difference-in-unix-shell/m-p/3327451#M873720</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-12T00:48:56Z</dc:date>
    </item>
  </channel>
</rss>

