how to get the last day /No. of days of "x" month

# Thread: how to get the last day /No. of days of "x" month

1. jpn
Senior Member
Join Date
Dec 1969
Posts
687

## how to get the last day /No. of days of "x" month

I wanted to get the last date(31st May for Eg) of the month as well as the number of days of a desired month.<BR><BR>Thanks for input & time.<BR><BR>Cheers <BR><BR>Jay

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

## Ummm...can I ask a dumb question?

What&#039;s the difference?<BR><BR>Doesn&#039;t the last day of a month have exactly the same number as the number of days *IN* the month???<BR><BR>It would be kind of weird to have May 31st be the last day of the month and yet have, say, 27 days in the month? Or 35 days, for that matter?<BR><BR>&#060;%<BR>firstOfMonth = DateSerial( YrNum, MoNum, 1 )<BR>lastOfThatSameMonth = DateSerial( YrNum, MoNum + 1, 0 )<BR>%&#062;<BR><BR>Yeah, really. The "zero-eth" day of the *next* month is the last day of the given month. (And you don&#039;t have to worry about December to January transition, even. It all works right.)<BR><BR>You can read this in the docs for DateSerial in the VBScript reference (link in left panel of this page).<BR><BR>

3. jpn
Senior Member
Join Date
Dec 1969
Posts
687

## Well after posting, I realised...sorry....it was d

Thanks..Bill..<BR><BR>Yes you are right...and I am sorry about that..<BR><BR>

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

## I was really just laughing...

...about it. You will note that I still gave you the answer.<BR><BR>Oh...not quite!<BR><BR>To get the DAY of the lastDayOfTheMonth, of course, you just use the DAY function.<BR><BR>So:<BR><BR>&#060;%<BR>lastOfMonth = DateSerial( theYear, theMonth+1, 0 )<BR>lastDayNumber = Day( lastOfMonth )<BR>%&#062;<BR><BR>Sorry! I guess, from the point of view of VBScript, there *is* a difference, after all.<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
•