1. ## Difference between dates

Hey Guys...
I need to ask for someone to explain the program to wri:
give the program 2 dates
day,mnonth,year
an anozer one
day,month,year
and then it gives the difference....my proble is in one thing....sometimes there are month which are 30,30,28..it differs!! ??
any help

Can it be any year from 2000BC to thousands of years in the future, or are we only concerned with "around now" dates [e.g. 10-20 years in the past until current or a few years ahead of now]. If it is a wide-ranging date, you have to take into account changes in calendars [perhaps] as well as the rather complex math to figure out if a particular year is a leapyear or not [and I don't really know WHAT happens before leap-years came into account].

What library functions, if any, are you allowed to use?
For example, can you use standard C time functions (e.g. difftime)?

Do you want the difference in years, months, days, or just as number of days between two dates.

--
Mats

3. Forgive me that the below data validator is in c++ but this may point you in the right direction

HOW TO MAKE DATE VALIDATOR PROGRAM IN C++
http://www.cplusplus.com/forum/general/3094/

4. sometimes there are month which are 30,30,28..it differs!!
How about running thorough each month in the current year and using an if statement to get the length? Also remember to check for leap year in feburary.

5. Well..I want the just the number of days in between the two dates..but,I will check difftime
Thanks everyone

6. Thanks BobSO327...and by the way difftime is for seconds !! not days
thanks anyways

7. Originally Posted by DaniiChris
Thanks BobSO327...and by the way difftime is for seconds !! not days
thanks anyways
Do you think it would be possible to convert seconds to days?

[Hint: 15180h]

--
Mats

8. You can derive the days from it tho: days = seconds / xxxx

9. Originally Posted by mike_g
You can derive the days from it tho: days = seconds / XXXX <modifed to hide the correct numer in case Mike_g edits his post>
Argh. Let 'em hang for a bit before giving the answer directly... ;-) The memory of having to calculate it/come up with it will stay much longer than being given it as a "this is the number you need" - unless you have a very good memory and remember those things immediately, it's much better to learn the process of how to calculate it, both for the learning experience as well as to actually have more in the brain to connect to the result.

--
Mats

10. Ok, I'll let him work it out

11. 1. Convert dates into Unix timestamps
2. Subtract timestamps from eachother
3. Convert the result into a date
4. Subtract 1970 from the year number, 1 from month, 1 from day

This way you get the difference using years, months, days, and possibly hours, minutes and seconds.