Calculating the number of sec's elapsed between two time intervals?

How can i calculate the number of seconds elapsed between two times intervals...
Convert your times to seconds and subtract...
please i need it more specific
Have you got the time intervals?
no actualy i didnt starrt nothing i dont know the formula to use i have to calculate the number of seconds elapsed between two times intervals...
for example i define a date for example from 1/1/2005 and i ask the user to put the year month day (yyyy mm dd) and the hour min sec (hh mm ss) and then i want to calculate the number of seconds elapsed betwen the given date from the user and the 1/1/2005!!
You can use something like this:
1
2
3
4
5
6
7
8
9
10
tm time1, time2;
time1.tm_year = 2005 - 1900;//years counted staring from 1900
time1.tm_mon = 0;//Jan == 0, Feb == 1 ... Dec == 11
time1.tm_mday = 1;// 1 - 31
time1.tm_hour = 0;// 0 - 23
time1.tm_min = 0;//0 - 59
time1.tm_sec = 0;// 0 - 59
//set values for time2...
time_t secs1=mktime(&time1), secs2=mktime(&time2);//convert into seconds numbers
time_t difference_in_seconds = secs2 - secs1;


Documentation:
http://www.cplusplus.com/reference/clibrary/ctime/tm.html
http://www.cplusplus.com/reference/clibrary/ctime/time_t.html
http://www.cplusplus.com/reference/clibrary/ctime/mktime.html
There are 60 seconds in a minute.
There are 60 minutes in an hour.
There are 24 hours in a day.
There are either 365 or 366 days in a year.

Compute the number of days between 01/01/2005 and the date the user entered. Multiply by 24 * 60 * 60 = 86400 to get a number of seconds. Add to that result the number of seconds elapsed in the day the user entered.
really thanks but i need somethink more detailed and more extended.... and im a bigginer and i dont know how to use libraries....so is a little bit difficult for me
jsmith thanks i will try smth now:D
#include <iostream>

using namespace std;

int main()

{
//Declaring the Variables
int year, month, days, hours, minutes, seconds;
cout << "Your year must be 2000 or greater";
do
{
cout << "Please enter a date in format (YYYY MM DD)";
cin >> year >> month >> days;

if (year<2000)
{
cout << "Ivalid year" << endl;
}

if ((month<=0) && (month>12))
{
cout << "Invalid month" << endl;
}

if ((day<=0) && (day>31))
{
cout << "Invalid day" << endl;
}
}

while ((year < 2000) || ((month<=0) && (month>12)) || ((day<=0) && (day>31)));

do
{
cout << "Please enter the valid year (example YYYY)";
cin >> year;
cout << "Please now enter the month (example MM)";
cin >> month;
cout << "And now enter the day (example DD)";
cin >> day;
}




this is what i done until now im really bored i dont know how to keep going can anybody help me???
If you're stuck just ask Simon for help.

Oh no, secrets out!
Topic archived. No new replies allowed.