469,271 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Return Number of Days In a month.

I am wanting to create my own calendar asp module.

Are there any functions in vbscript that return the number of days in a
particular month depending on what year it is ??
Jul 19 '05 #1
5 15457
You could do this:

iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

If you don't have a value of "yourDate" and just have a month and a year,
do:

yourDate = yourYear & "-" & yourMonth & "-1"

What the code above is doing is taking your date, adding one month to it,
then subtracting one day.

Ray at work
"Adam Knight" <ad**********@optusnet.com.au> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
I am wanting to create my own calendar asp module.

Are there any functions in vbscript that return the number of days in a
particular month depending on what year it is ??

Jul 19 '05 #2
Ray,

iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

DateAdd("m",1, yourDate) -- so it goes to June 19 (assuming yourDate is
May19)
DateAdd("d",-1,theAbove) -- so it goes to June 18
Day(theAbove) -- 18

Am I missing something?
TomB
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:eW**************@TK2MSFTNGP10.phx.gbl...
You could do this:

iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

If you don't have a value of "yourDate" and just have a month and a year,
do:

yourDate = yourYear & "-" & yourMonth & "-1"

What the code above is doing is taking your date, adding one month to it,
then subtracting one day.

Ray at work
"Adam Knight" <ad**********@optusnet.com.au> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
I am wanting to create my own calendar asp module.

Are there any functions in vbscript that return the number of days in a
particular month depending on what year it is ??


Jul 19 '05 #3
I was going with a "yourDate" as being the first of the month. If it's just
an arbitrary date, then you (or Adam?) could do:

myDate = "2004-05-19"
yourDate = Year(myDate) & "-" & Month(myDate) & "-1"

first. That will then do:
- go to beginning of month
- add one month
- subtract one day

Ray at work
"TomB" <sh*****@hotmailXXX.com> wrote in message
news:uI****************@TK2MSFTNGP11.phx.gbl...
Ray,

iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

DateAdd("m",1, yourDate) -- so it goes to June 19 (assuming yourDate is
May19)
DateAdd("d",-1,theAbove) -- so it goes to June 18
Day(theAbove) -- 18

Am I missing something?
TomB
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:eW**************@TK2MSFTNGP10.phx.gbl...
You could do this:

iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

If you don't have a value of "yourDate" and just have a month and a year, do:

yourDate = yourYear & "-" & yourMonth & "-1"

What the code above is doing is taking your date, adding one month to it, then subtracting one day.

Ray at work
"Adam Knight" <ad**********@optusnet.com.au> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
I am wanting to create my own calendar asp module.

Are there any functions in vbscript that return the number of days in a particular month depending on what year it is ??



Jul 19 '05 #4
Function GetDaysInMonth(dtmDate)
If IsDate(dtmDate) Then
dtmFirstOfMonth = DateSerial(Year(dtmDate),Month(dtmDate),1)
GetDaysInMonth = Day(DateAdd("d",-1,DateAdd("m",1,dtmFirstOfMonth)))
End If
End Function

'from dlbjr

'Unambit from meager knowledge of inane others,engender uncharted sagacity.
Jul 19 '05 #5
"dlbjr" <oo**@iforgot.com> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl...
Function GetDaysInMonth(dtmDate)
If IsDate(dtmDate) Then
dtmFirstOfMonth = DateSerial(Year(dtmDate),Month(dtmDate),1)
GetDaysInMonth = Day(DateAdd("d",-1,DateAdd("m",1,dtmFirstOfMonth))) End If
End Function

'from dlbjr

'Unambit from meager knowledge of inane others,engender uncharted sagacity.


Day(DateSerial(Year(dtmDate),Month(dtmDate)+1,0))
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by josepe | last post: by
7 posts views Thread by developer | last post: by
1 post views Thread by Phil Endecott | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.