Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date and time conversion-Unix 1

Status
Not open for further replies.

sadler21

IS-IT--Management
Aug 27, 2002
1
US
Is there a script in in Unix that will convert dates ands times into total minutes or hours and minutes. For example, I have a process that starts on August 31, 2002 at 10p.m. and ends on September 1, 2002 at 3a.m.; I need on a final report the amount of hours and minutes the entire process took to complete. Thanks, Dana (asking for a friend)
 
Sadler:

I've seen scripts that jumped thru mighty hoopes trying to solve datetime problems like yours. If you can, I'd look at the GNU versions of awk and date. Here's a gawk function I acquired:

#!/bin/sh
# time.sh
# Author: Julian Cates
#
# Figure what a date was/will be, given an offset
# from current day:
#./time.sh -7
# Thu May 17 10:49:06 CDT 2001
#==========================================================
ME=`basename ${0}`
if [ $# -ne 1 ]
then echo "Usage is $ME [+/-] # of days"
else
/usr/local/gnu/bin/gawk -v days=$1 'BEGIN{
target_date = systime()+(86400*days)
datestring = strftime("%c", target_date)
printf "%s\n\n",datestring }'
fi

If you're up for Perl, you might check out Mike Lacey's most excellent FAQ at:

faq80-953

in the General Unix forum.

Regards,

Ed
 
Depending on your shell, precede your shell command with the word "time"

[tt]aix/root:/# time ls -l /
total 788
(data snipped)

real 0m0.02s
user 0m0.00s
sys 0m0.02s
aix/root:/# [/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top