Thread: how can i get the number of days between two dates?

  1. #1
    Registered User
    Join Date
    Feb 2008

    how can i get the number of days between two dates? new i just want to ask..some few questions about my homework coz i dont know what code i am going to use..
    i can't fully understand the codes that are in the FAQ..

    please explain it here..

    for example..
    i entered a date of march 21 2007, and I entered a date of april 3, 2007
    i want to get the difference of the days of the two dates..

    what code am i going to use and how can i apply it?
    sorry for my bad english >_<

    please help..
    sorry for the inconvinence

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    If you can get the date into a "time_t" type, you can use difftime() which is a standard function in the C runtime library. difftime gives you the number of seconds between two time values, and time in itself is "date and time" combined.

    And as a help, 24 * 60 * 60 -> 86400, so the days is "seconds/86400".

    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
    Join Date
    Mar 2005
    Mountaintop, Pa
    Possibly calculate the Julian day number for beginning date and ending date. Then subtract the beginning Julaian day number from the ending Julian day number.

    A formula for calculating Julian day numbers can be found at this Julian day wiki

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. Algorithm help
    By mmyers1 in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2004, 09:56 PM
  5. C++ number of days between 2 dates?
    By Rain1522 in forum C++ Programming
    Replies: 1
    Last Post: 03-13-2002, 09:09 PM