1827243 Members
2347 Online
109716 Solutions
New Discussion

Diff between times

 
SOLVED
Go to solution
weller
Advisor

Diff between times

Hi,

I will find difference between
2 times in data format in textfile. For Example between Thu 6/12 9:49 and Thu 6/11 17:00 May be exist program or funkiton as shell or awk or perl. All Infos welcome.
Sorry for very bad "Englisch"
Thanks
7 REPLIES 7
Michael Steele_2
Honored Contributor

Re: Diff between times

For a text file with this formatted entry:

William ted Thu 6/12 9:49 fred ralph
bill ted Thu 6/11 17:00 fred ralph

Using 'grep' and 'sort':

grep '6/11' file.txt | sort

...displays...

bill ted Thu 6/11 17:00 fred ralph
William ted Thu 6/12 9:49 fred ralph
Support Fatherhood - Stop Family Law
weller
Advisor

Re: Diff between times

Michael thanks,

but my problem lies elsewhere,
I has two time stamps and would like to know, like many time past between them.

Michail Weller
Darren Prior
Honored Contributor

Re: Diff between times

Hi,

This sounds like a tricky task to me!

Do you need to find the difference between them in hours, or whole days?

For days you will need to search the forum for A. Clay Stephenson's caljd.sh script. You will need to use sed or awk to extract the date as 6/12 and then use the appropriate options to caljd to output the Julian date. You can then subtract one Julian date from the other.

If you need to calculate the difference in hours or minutes then use the same approach, but you'll need to convert the 9:49 and 17:00 to minutes since midnight and perform a calculation on them.

regards,

Darren
Calm down. It's only ones and zeros...
Jean-Louis Phelix
Honored Contributor
Solution

Re: Diff between times

Hi,

Or you can also compile this one using make :

hp:FORUMS> diffdate "6/12 9:49" "06/10 09:50"
Difference is 1 days 23 hours 59 minutes

You will perhaps need to better deal with controls and year ...

Regards.
It works for me (© Bill McNAMARA ...)
weller
Advisor

Re: Diff between times

Thanks !!!

that was exact, which I had used

Michail Weller
weller
Advisor

Re: Diff between times

I believe,
thus month functioned also correctly must one in line 39 instead of (argv[1 ] ]) (argv[2 ]) write.

Still times thank you
Michail Weller
Jean-Louis Phelix
Honored Contributor

Re: Diff between times

Hi,

I wrote perhaps too fast ... Thank you for your correction. I'll keep it perhaps for another time in the forums.

Best regards.
It works for me (© Bill McNAMARA ...)