ADSM-L

Re: Date format manipulation.

2002-03-05 11:10:45
Subject: Re: Date format manipulation.
From: Thomas Denier <Thomas.Denier AT MAIL.TJU DOT EDU>
Date: Tue, 5 Mar 2002 11:07:20 -0500
>  Hi Just shell script question.
> I want to manipulate dates and get diff of two variables.
> But result I want in hrs:min:sec.
> Start_Time=`date +%H%M%S`
> sleep 1                                 (Just for testing diff is 1)
> End_Time=`date +%H%M%S`
> TOTAL_Time=`echo "$End_Time - $Start_Time"|bc`
> echo $TOTAL_Time
>
> But result I want in hrs:min:sec ????I want to be very simple don't want to
> use sed and awk.

I would use the SECONDS environment variable rather the date command. This
eliminates the problem of dealing with colons and base 60 conversion in the
input to the subtraction. The sequence below gets fairly close to doing
what you want. It does not insert colons. It will supply only one pair of
output digits if the time is less than 60 seconds, and only two pairs if
the time is greater than 59 seconds but less than 3600 seconds.

START=$SECONDS
command
echo $SECONDS $START - 60 o p|dc
<Prev in Thread] Current Thread [Next in Thread>