Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default DateAdd question

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default DateAdd question

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dateadd function Dr. Maunuk Excel Discussion (Misc queries) 2 September 28th 07 07:32 AM
dateadd The BriGuy[_2_] Excel Programming 12 March 30th 07 08:02 PM
dateadd The BriGuy[_2_] Excel Discussion (Misc queries) 1 March 29th 07 06:51 PM
DateAdd johnboy Excel Programming 2 June 17th 06 10:58 PM
DateAdd Michael Wise[_7_] Excel Programming 1 August 27th 04 07:40 PM


All times are GMT +1. The time now is 02:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"