Date command output conversion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date command output conversion
# 1  
Old 10-20-2010
Date command output conversion

hi all,

i need to measure time difference between the time a process started, to the time it ended. i am assuming the following are the steps:

1. output 'date' command at start time
2. output 'date' command at end time
3. subtract the two

question is, how do i subtract the two time outputs, when that output looks like: "Wed Oct 20 06:20:22 UTC 2010" as an example.

So basically, I need the result of the subtraction to look something like: 1h 22m 09s.

Appreciate any assistance I can get.
Thanks!
# 2  
Old 10-20-2010
Which shell are you running? Date manipulation is not the easiest thing to do in Unix. There have been multiple posts on this within these forums.
Check this. It's a very useful post on everything related to date Smilie

Meanwhile if you have the GNU version of 'date' you could just run:
Code:
date +%s

This outputs seconds since `00:00:00 1970-01-01 UTC' (a GNU extension).
Thus you would end up getting date as 1287584703, etc. This is easy to store and subtract.
# 3  
Old 10-20-2010
Which system do you process?

Maybe you must use time command

simply ex
Code:
# time ps -ef 1>/dev/null
real    0m0.038s
user    0m0.005s
sys     0m0.033s

# 4  
Old 10-20-2010
thanks for the responses.
follow up question: how do you get the "1287584703" back to a format like "1h 22m 09s"
thanks!
# 5  
Old 10-21-2010
See my comment in this thread (very similar request to yours).

https://www.unix.com/shell-programmin...e-process.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Date conversion

Hi , we have a string with yyyymmdd format . how to know which date it is ? example:20120712-->sunday 20150228-->saturday 20140431-->invalid please suggest commands which work on below os : SunOS 5.10 shell: bash shell Thanks, Srinath. (10 Replies)
Discussion started by: srinadhreddy27
10 Replies

2. Solaris

Solaris 9 Zone : Date command in crontab shows delayed(One Hour) output

SOLARIS 9 Zone : date command in crontab shows delayed(One Hour) output Hi folks, the date command shows the correct date and time, How ever, if the date command executed through crontab in any form of scrip the output shows as one hour delayed, similar to date -u.. Can some one help in... (12 Replies)
Discussion started by: judi
12 Replies

3. Shell Programming and Scripting

awk - append date to output of a command

Hi all; I am running a script:/var/tmp/gcsw -ne | grep "State:2" | wc that gives me output like:80 480 6529 but i need this output as:2013-01-18 13:00 -> 80 480 6529 (1 Reply)
Discussion started by: gc_sw
1 Replies

4. Shell Programming and Scripting

Julian date to Calendar date conversion

Hi all, I require to convert julian date to normal calander date in unix for eg julian date=122 now i want corresponding calander date ---------------------------------------- gr8 if give very small command/script and please explain the steps as well(imp) Thanks ... (3 Replies)
Discussion started by: RahulJoshi
3 Replies

5. UNIX for Advanced & Expert Users

Date Conversion on output string from awk

Hi, I would like to convert the output from awk function to date and print on the screen. Example : echo "Start Date: May 24 2010" | gawk -F": " '{print $2}' Output : May 04 2010 I want this to be converted to 2010/05/24 Can i use date function here and how? Thanks, Deepika (2 Replies)
Discussion started by: deepikad
2 Replies

6. Solaris

Bad command error for date conversion

Hi, Iam trying to convert date and time to milliseconds which iam using in a script on Sun Solaris. I have searched the posts on the forum but i could not get any solution. The format iam using in script is: date -u "Thu Dec 24 00:01:00 EST 2009" But i get a bad command error. ... (6 Replies)
Discussion started by: jyothi_wipro
6 Replies

7. Shell Programming and Scripting

Conversion of date to Julian date

Hi Gurus, Need help in Conversion of date(2007-11-30) to Julian date(YYDDD)... '+%J' 2007-11-30 to 'YYDDD' Thanks (4 Replies)
Discussion started by: SeenuGuddu
4 Replies

8. Shell Programming and Scripting

Date conversion

Hi, I have the string YYYYMMDDHHMMSS like 20090801204150 and I need to convert it using the unix command date in the format: date "Saturday, 1 August 2009 20:40:59" All in one single Unix line if this is possible. What's the correct syntax? Steve Hagi (6 Replies)
Discussion started by: hagimeno
6 Replies

9. Shell Programming and Scripting

Date conversion

Hi I want to convert MAY 05 2005 01:15:00PM date format to 2005/05/05 01:15:00PM . CAn somebody suggest me a code ,I am new to unix shell programming. Thanks Arif (21 Replies)
Discussion started by: mab_arif16
21 Replies

10. Shell Programming and Scripting

date conversion

file1 E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538 E109,0,06-mar-07,0,E001,E001,A,78000,6500,37.5 E110,0,09-dec-2008,0,E001,E001,A,56000,4666.667,26.923077 E104,0,06/04/1994,0,E001,E003,A,95000,7916.667,45.673077... (14 Replies)
Discussion started by: charandevu
14 Replies
Login or Register to Ask a Question