PC Review


Reply
Thread Tools Rate Thread

DateAdd question

 
 
CG Rosén
Guest
Posts: n/a
 
      17th Jul 2007
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 With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      17th Jul 2007
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateAdd question azu_daioh@yahoo.com Microsoft Access Queries 1 29th Jun 2007 02:52 AM
DateAdd Question knitter via AccessMonster.com Microsoft Access Queries 1 17th May 2007 10:19 PM
DateAdd Question =?Utf-8?B?RVJpY2g=?= Microsoft Access Queries 3 9th Oct 2006 05:07 PM
DateAdd question Junior Microsoft Access Form Coding 2 4th Aug 2004 08:00 PM
Dateadd question MarkH Microsoft Access Form Coding 1 30th Jun 2004 03:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:49 AM.