Solved

"date2 - date1": elapsed time in hrs, mins, and secs

Posted on 2004-08-06
6
914 Views
Last Modified: 2010-04-21
How to calculate the elapsed time in hrs, mins, and secs:

For example, in the script, it has

d1=`date`
......
d2=`date`

How to get the time difference between d2 and d1.

Thanks.
0
Comment
Question by:geermu
6 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 63 total points
ID: 11733410
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11748780
As an alternative.

man time
0
 
LVL 7

Assisted Solution

by:glassd
glassd earned 62 total points
ID: 11771799
Perl's Date::Calc module is ideal for this task.
0
 
LVL 5

Expert Comment

by:ITcrow
ID: 11865515

You have multiple options here:

perl:  
$start_time = time();
<Your Script Here>
$end_time  = time();
$time_taken =  $start_time - $end_time;

Or use some CPAN module: benchmark, Date::Calc, etc.

*nix Shell Cmd Line:
prompt> time <Your Script Here>

I am not aware which shell you are working in. Otherwise I could have suggested
a shell specific calculation.

Use of perl will make it Shell and OS independent, which is a good thing in long run.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to backup and restore the DHCP configuration on Solaris 9 7 55
How to clone solaris 10 machine 33 149
Bash Script to Analyze Oracle Schemas 11 117
lunix and unix command 21 86
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question