Link to home
Start Free TrialLog in
Avatar of MIKEV
MIKEV

asked on

Incrementing dates

I'm just trying to create a loop that will increment a date by a day each time:

TestDate = "3/27/2005"
For x = 1 To 7
    Debug.Print TestDate + Day(x)
Next x

Seems pretty simple... Here's the results:

4/27/2005
3/28/2005
3/29/2005
3/30/2005
3/31/2005
4/1/2005
4/2/2005

See the first date?  What's up with that?  Why would +day(1) increment the MONTH?  Why does the month then decrease by one?  I don't get this...

So I try this:

TestDate = "3/27/2005"
For x = 1 To 7
    TestDate = TestDate + Day(x)
    Debug.Print TestDate
Next x

Results:

4/27/2005
4/28/2005
4/30/2005
5/3/2005
5/7/2005
5/12/2005
5/18/2005

???

Why does this make no sense whatsoever?
Thanks!
Avatar of MIKEV
MIKEV

ASKER

Oh, I can see my error in the second example above, it's adding 1 days, then 2 days, etc.  This is better:

TestDate = "3/27/2005"
For x = 1 To 7
    TestDate = TestDate + Day(1)
    Debug.Print TestDate
Next x

4/27/2005
5/28/2005
6/28/2005
7/29/2005
8/29/2005
9/29/2005
10/30/2005

Now it's inreasing the month?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or this if you using DateSerial, DateAdd functions:

TestDate = DateSerial(2005, 3, 27)
    For x = 1 To 7
        TestDate = DateAdd("d", 1, TestDate)
        Debug.Print TestDate
    Next x