DateAdd("M", 1, Month(NOW))

Thread: DateAdd("M", 1, Month(NOW))

1. Senior Member
Join Date
Dec 1969
Posts
150

DateAdd("M", 1, Month(NOW))

I am trying to the number of next month e.g. 6<BR><BR>I expected to get the result I want using nextMonth = DateAdd("M", 1, Month(NOW))<BR><BR>but I get: nextMonth = 2/4/1900

2. Medieval Dude Guest

Oh no! Y2K!!!

Just kidding.<BR>Try this:<BR>Month(DateAdd("M", 1, NOW))

3. Senior Member
Join Date
Dec 1969
Posts
96,118

Should be DateAdd("M",1,Now)

The Month in there is wrong!<BR><BR>Month(anyDateTimeValue) always returns simply a number from 1 to 12. Period.<BR><BR>And then the number, used in DateAdd, becomes the number of days since 12/30/1899.<BR><BR>SO: Month(Now) is 5. 5 Days after 12/30/1899 is 1/4/1901. And one month from that is 2/4/1901. Makes great sense to me!<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
150

RE: Should be DateAdd(

am I being really thick? <BR><BR>DateAdd("M",1,Now) is giving me: 6/7/2001 11:11:47 <BR>how do I round that up to being: 6

5. Medieval Dude Guest

See my answer <eop>

.

6. Senior Member
Join Date
Dec 1969
Posts
96,118

Do not use DateAdd

If all you want is the number of the month one month from now:<BR><BR>&#060;%<BR>nextMonthNumber = Month(Now) + 1<BR>%&#062;<BR><BR>But what happens when December comes along???<BR><BR>Now you&#039;ll add 1 to 12 and get 13. <BR><BR>SO...<BR><BR>Just what are you trying to accomplish????<BR><BR>You *could* do:<BR><BR>Month( DateAdd( "M", 1, Now ) )<BR><BR>and that will always give you the right answer. Giving you 1 when the current month is December, for example. But then you&#039;ll have to do something similar to figure out you&#039;ve changed years, yes?<BR><BR>Year( DateAdd( "M", 1, Now ) )<BR><BR>So if your going to do that, why not just:<BR><BR>&#060;%<BR>aMonthFromNow = DateAdd( "M", 1, Now )<BR>theMonth = Month( aMonthFromNow )<BR>theYear = Year( aMonthFromNow )<BR>...<BR>%&#062;<BR><BR>Look at other DateTime functions in the VBS manual.<BR><BR>

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•