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

This is a discussion on how can i get the number of days between two dates? within the C Programming forums, part of the General Programming Boards category; hi..im new i just want to ask..some few questions about my homework coz i dont know what code i am ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    18

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

    hi..im 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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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".

    --
    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
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    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
    Posts
    5,006
    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, 04:33 AM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 10:53 PM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 05:25 AM
  4. Algorithm help
    By mmyers1 in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2004, 10: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

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