Operating System - Linux
1752821 Members
4912 Online
108789 Solutions
New Discussion юеВ

Time and date calculation

 
SOLVED
Go to solution
Henry Chua
Super Advisor

Time and date calculation

Hi Guys,

I need to write a program in C or shell to calculate the time interval between 2 timing... e.g.

Start=07/08/2005,14:05:29
End =07/08/2005,16:28:46

What i find difficult is if say start is at 29/02/2005 and end is at 1/03/2005.. how can i know how many days in between this 2?

Is there anyway?

Thank u.
2 REPLIES 2
Leif Halvarsson_2
Honored Contributor

Re: Time and date calculation

Hi,

Have you looked at Clay Stephenssons "Date Hammer" ?
You can find it here:
http://www.cmve.net/~merijn/
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Time and date calculation

In C, you fill out a struct tm variable for each of the times and then call mktime() for each to give you time_t seconds for each. These values represent seconds since 1-Jan-1970 00:00:00 UTC. Find the difference between these two time_t values and divide by 86400 and you have the number of days different. Man mktime for details.
If it ain't broke, I can fix that.