Thread: determine time between two dates

  1. #1
    Registered User
    Join Date
    Apr 2002

    determine time between two dates

    If I have six variables, startMonth, startDay, startYear, endMonth, endDay and endYear, all defined as ints, does anyone know about any algorythm/function that can subtract the end date (endMonth endDay and endYear) from start date (startMonth, startDay, startYear) and find the number of days, months and/or years in between the two dates.


  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Use the day and month variables to determine the number of days that have passed in each year and find the difference in those two values. Then take that difference and add the number of full years between the two dates multiplied by 365, that's the number of days between the two dates. From there you can easily calculate how many months and years have passed.

    My best code is written with the delete key.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    mktime() and difftime()
    Both in time.h
    Will tell you the difference in seconds
    Should be able to take it from there

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM