PDA

Click to See Complete Forum and Search --> : Days in Month


Serge
Oct 30th, 1999, 04:35 AM
Sure thing:


Public Function GetlastDayofMonth(pDate As Date)
GetlastDayofMonth = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
End Function


Usage: GetlastDayofMonth YourDate

Example:

MsgBox "This year " & Format(Date, "mmmm") & " has " & GetlastDayofMonth(Date) & " days."



Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com




[This message has been edited by Serge (edited 10-30-1999).]

peteritv
Oct 30th, 1999, 04:39 AM
Yep, Serge's solution looks a lot better than mine (in the other post)....

DiGiTaIErRoR
Oct 30th, 1999, 04:41 AM
how bout u answer my question serge? u seem hella good :)

QWERTY
Oct 30th, 1999, 06:01 AM
THANKS

QWERTY
Oct 30th, 1999, 11:39 AM
Is there a function to determine total number of days is any month?

Thanks in advance

Serge
Oct 30th, 1999, 10:44 PM
DiGiTaIErRoR, what IS your question then?


Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com

zedar
Nov 11th, 1999, 03:35 PM
Is'nt it supposed to be like this ? (At least)

Whats the point of sending something in to the function if you don't use it ??
Whatever you send to this function it will return the current date's last day !!??

Public Function GetlastDayofMonth(pDate As Date)
GetlastDayofMonth = Day(DateSerial(Year(pDate), Month(pDate) + 1, 0))
End Function

/Zedar

Serge
Nov 11th, 1999, 06:01 PM
The thing is: you have to pass atleast the Month and a Year so the date can be calculated correctly. (If that's your question)


Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

tbostrup
Nov 15th, 1999, 07:44 PM
zedar is right.

The original code doesn't use the date variable passed to the function, but the Date function (thereby returning the number of days in the CURRENT month rather than the one in for the date specified).

HTH,
Tore.

Serge
Nov 15th, 1999, 08:11 PM
I don't understand. In the example I made, I did passed the current date (just for testing), but the function itself is Generic. So you can pass any date.

Regards,

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

Irochka
Feb 10th, 2000, 10:28 PM
Originally posted by Serge:
Sure thing:


Public Function GetlastDayofMonth(pDate As Date)
GetlastDayofMonth = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
End Function


Usage: GetlastDayofMonth YourDate

Example:

MsgBox "This year " & Format(Date, "mmmm") & " has " & GetlastDayofMonth(Date) & " days."



Regards,


Serge, thanks a lot this is really useful tip, the only thing is that in your function there should be pDate used instead of date in all your calculations.
Public Function GetlastDayofMonth( _
pDate As Date)
GetlastDayofMonth = Day(DateSerial(Year(Date), Month(Date) + 1, 0))

Serge
Feb 11th, 2000, 11:33 AM
Yep, I know I screwed up. That what happens when you type directly into the post (just a typo). LoL

------------------

Serge

Senior Programmer Analyst
sdymkov@microage.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)