how do you loop through date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ryanlt
    New Member
    • May 2010
    • 1

    #1

    how do you loop through date

    how do you integrate a date adding a year per loop. for example you start out in 2006 and it runs 5 times and you end up in 2010
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What data type are you using to hold the date? For instance if you are using time_t which holds the date as seconds since 1/1/1970 00:00:00 then all you need to do is add the number of seconds in each year (noting that a leap year has an extra day) for each loop iteration.

    If you are using a struct tm then you can just increment the year but will need to verify the day/month is still valid if you started on a leap day.

    Windows uses another time system holding 100nanosecond increments since some other date but again you just need to add the number of increments in the year.

    Comment

    Working...