how to get difference between two times
STARTING 06:12:23
SUCCESS 06:19:41 how to get diff of two times |
start
5:34:06 5:34:14 0:00:08 |
can someone do me a favor for the above
|
My advice would be to (1) convert your times (as you get them) to epoch time and (2) then take the difference of those two. You can then (3) convert the difference into a more human-friendly time format whenever you need.
Example (using your first request): Code:
06:12:23 or epoch time: 1230617543 http://www.epochconverter.com/ http://www.csgnetwork.com/epochtime.html The first website has short, but helpful discussions about how to compute epoch time from "human" formats and vice versa in various languages. Edit: I'm assuming that you want help doing this with a program and not that you just want us to do the math for you. |
Or use nano seconds -
Code:
date +%N |
You have also to check if the END time is smaller or greater than the START time. For example if a job starts at 23:45:09 and terminates at 00:23:18 you have to take in account the change of day in your calculations (to not mention the troubles introduced by the passage from/to the Daylight Saving Time).
Anyway, here is an example of what you can do: Code:
#!/bin/bash |
Quote:
This script will show you how to convert a time to seconds since the epoch. You can then compare the seconds. |
All times are GMT -5. The time now is 01:51 AM. |