Thread: Day countdown

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    8

    Day countdown

    Hi there,

    I am completely new to programming and need to learn it fast. I have been set the task of creating a day countdown in C. I need the programme to workout the difference between two dates and display the number of days inbetween that period.

    Could anyone put me in the right direction to help me code this. I have read basic tutorials, but am not sure where to go next.

    Thanks.

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    20

    Nostalgia

    Ahh, this is one of the first programs I ever wrote.

    Should be as simple as subtracting the days between the two dates if the months are equal to one another.
    Here are some snags you need to watch out for.

    Two dates in different months, this should not be to hard you only need to calc how many days the first date is away from the end of the month, how many months in between (if start month > end month+1 so long as they are contained within the same year), if the months in between are 30 or 31 day months and then add that to the # of the day in the ending day

    Watch out for dates that cross over years

    Watch out for leap years. Detect leap year function really helps here.

  3. #3
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    You want to find documentation functions provided in time.h (if you use C) or ctime (if you use C++) headerfile. You do not want to create the algorithm yourself - leapyears, daylight savings etc. take care of that

    To be more precise, you might want to know functions mktime() and difftime().

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    20
    Quote Originally Posted by Maz View Post
    You want to find documentation functions provided in time.h (if you use C) or ctime (if you use C++) headerfile. You do not want to create the algorithm yourself - leapyears, daylight savings etc. take care of that

    To be more precise, you might want to know functions mktime() and difftime().
    But where is the fun in that :P

  5. #5
    Registered User Maz's Avatar
    Join Date
    Nov 2005
    Location
    Finland
    Posts
    194
    The fun? I guess nowhere. But the author's style of putting the question let me to assume he is not in this just for fun I've been programming for fun and for my work - and believe me, while making it all yourself may be fun at times, it is not fun at all when someone is breathing at your neck...

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    8

    Smile

    Thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Should I learn a FULL language first?
    By Raeliean in forum Game Programming
    Replies: 8
    Last Post: 07-16-2005, 06:59 PM
  2. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  3. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM
  4. debug program
    By new_c in forum C Programming
    Replies: 3
    Last Post: 03-18-2002, 11:50 PM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 03:50 PM