Difference between dates

This is a discussion on Difference between dates within the C Programming forums, part of the General Programming Boards category; Hey Guys... I need to ask for someone to explain the program to wri: give the program 2 dates day,mnonth,year ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    48

    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

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What are your restrictions?
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    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. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    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. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    48
    Well..I want the just the number of days in between the two dates..but,I will check difftime
    Thanks everyone

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    48
    Thanks BobSO327...and by the way difftime is for seconds !! not days
    thanks anyways

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by DaniiChris View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You can derive the days from it tho: days = seconds / xxxx
    Last edited by mike_g; 08-18-2008 at 07:04 AM.

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mike_g View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Ok, I'll let him work it out

  12. #12
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    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.

    Last edited by maxorator; 08-18-2008 at 08:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Review required for program of date difference
    By chottachatri in forum C Programming
    Replies: 6
    Last Post: 10-31-2008, 11:46 AM
  2. Getting the difference between dates
    By Leftos in forum C Programming
    Replies: 7
    Last Post: 01-19-2008, 11:49 PM
  3. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  4. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 05:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21