Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Good day Group,
Have some problem to understand the DateAdd function. Seems that if the start date is a month with a last date of 28 and 30 the DateAdd function does not add a month in the way that the following month will be shown with its last date. It works if the start date is a month that with a last date of 31. The problem can be checked by following code. Is this the way it is supposed to be or am I doing this the wrong way? str = "2006-02-28" For i = 1 To 5 d = DateAdd("m", i, str) MsgBox d Next i Brgds CG Rosen |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Adding a 1 to the number of the month of the date is a reasonable
interpretation, but obviously not what you want. This represents a way to get the last day. You would have to add your own logic to determine which approach to use when. Sub AA() Dim dStr As Date Dim d As Date, d1 As Date dStr = DateSerial(2006, 2, 28) For i = 1 To 5 d = DateAdd("m", i, dStr) d1 = DateSerial(Year(dStr), Month(dStr) + i + 1, 0) MsgBox d & vbNewLine & d1 Next i End Sub -- Regards, Tom Ogilvy "CG Rosén" wrote: Good day Group, Have some problem to understand the DateAdd function. Seems that if the start date is a month with a last date of 28 and 30 the DateAdd function does not add a month in the way that the following month will be shown with its last date. It works if the start date is a month that with a last date of 31. The problem can be checked by following code. Is this the way it is supposed to be or am I doing this the wrong way? str = "2006-02-28" For i = 1 To 5 d = DateAdd("m", i, str) MsgBox d Next i Brgds CG Rosen |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Dateadd function | Excel Discussion (Misc queries) | |||
dateadd | Excel Programming | |||
dateadd | Excel Discussion (Misc queries) | |||
DateAdd | Excel Programming | |||
DateAdd | Excel Programming |