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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
TestDate = DateSerial(2005, 3, 27)
For x = 1 To 7
TestDate = DateAdd("d", 1, TestDate)
Debug.Print TestDate
Next x
ASKER
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?