DateAdd +weeks dropping a few days

R

Robert Zeurunkl

This one actually got interesting. After a bit of research, here's what
I found:

Starting with 1/1/2005, and adding years (52 weeks at a time), I get
the following results:

1 Week: 12/31/2005 -0 days
2 Weeks: 12/30/2006 -1 days
3 Weeks: 12/29/2007 -2 days
4 Weeks: 12/27/2008 -4 days
5 Weeks: 12/26/2009 -5 days
6 Weeks: 12/25/2010 -6 days
7 Weeks: 12/24/2011 -7 days
8 Weeks: 12/22/2012 -9 days
9 Weeks: 12/21/2013 -10 days
10 Weeks: 12/20/2014 -11 days


I think what happens is that I loose one day PER YEAR because I add the
year, but not the extra DAY to bump me over to the next year. Then you
notice that I lose an EXTRA day in 2008 and 2012. Both leap years. SO
leap years are partially at the root. How bout that?

Finally, 2014 IS a leap year, but nothing odd happens because we don't
get to it. My test date is january 1.

In the end, I needed to take the results from DateAdd() and add one day
for each year spanned, but also one day for each leap year encountered
in the date range.

B.
 
D

Douglas J. Steele

Why are you adding multiples of 52 weeks if you really want to add years?
 
B

BruceM

Last I heard 2014 is not a leap year. The calculation seems to be working
perfectly, since 52 weeks is 364 days. Try adding a year. Access can sort
out leap years if you do that.
 
M

Mike Painter

Robert said:
This one actually got interesting. After a bit of research, here's
what I found:

Starting with 1/1/2005, and adding years (52 weeks at a time), I get
the following results:

1 Week: 12/31/2005 -0 days
2 Weeks: 12/30/2006 -1 days
3 Weeks: 12/29/2007 -2 days
4 Weeks: 12/27/2008 -4 days
5 Weeks: 12/26/2009 -5 days
6 Weeks: 12/25/2010 -6 days
7 Weeks: 12/24/2011 -7 days
8 Weeks: 12/22/2012 -9 days
9 Weeks: 12/21/2013 -10 days
10 Weeks: 12/20/2014 -11 days


I think what happens is that I loose one day PER YEAR because I add
the year, but not the extra DAY to bump me over to the next year.
Then you notice that I lose an EXTRA day in 2008 and 2012. Both leap
years. SO leap years are partially at the root. How bout that?

52*7 = 364.
There are 365 days in a year.
 
Top