|
 |
access thread: Number of days in a Month
Message #1 by "Maha Arupputhan Pappan" <mahap@p...> on Thu, 13 Dec 2001 10:01:13
|
|
I using Access 2000 and need assistance to get the number of days in a
month. For example, number of days in December is 31 days.
Thanks,
Maha
Message #2 by Walt Morgan <wmorgan@s...> on Thu, 13 Dec 2001 07:10:00 -0600
|
|
Maha,
you can use DateSerial(Year(Now(),Month(Now(),0) to obtain last day of
previous month.
Something like this:
FUNCTION LastDayOfMonth(nYear as Integer,nMonth As Integer)
Dim EOM as date
Dim LastDay as Integer
EOM = DateSerial(Year(nYear),Month(nMonth),0)
EOM = Format(EOM,"mm/dd/yyyy")
LastDay = Day(EOM)
LastDayOfMonth = Day(EOM) 'Last Day of Previous Month
END Function
This should get you started.
Walt
>I using Access 2000 and need assistance to get the number of days in a
>month. For example, number of days in December is 31 days.
>
>Thanks,
>Maha
Message #3 by "Gerald, Rand" <RGerald@u...> on Thu, 13 Dec 2001 11:25:23 -0600
|
|
Walt,
Here is some code:
' This function calculates the number of days in a month.
' Input: dIn - Any date in the desired month.
' Output: DaysInMonth - The number of days in the month.
Public Function DaysInMonth(dIn As Date) As Integer
Dim NextMonth As Date
Dim EndOfMonth As Date
NextMonth = DateAdd("m", 1, dIn)
EndOfMonth = NextMonth - DatePart("d", NextMonth)
DaysInMonth = DatePart("d", EndOfMonth)
End Function
Rand
-----Original Message-----
From: Walt Morgan [mailto:wmorgan@s...]
Sent: Thursday, December 13, 2001 7:10 AM
To: Access
Subject: [access] Re: Number of days in a Month
Maha,
you can use DateSerial(Year(Now(),Month(Now(),0) to obtain last day of
previous month.
Something like this:
FUNCTION LastDayOfMonth(nYear as Integer,nMonth As Integer)
Dim EOM as date
Dim LastDay as Integer
EOM = DateSerial(Year(nYear),Month(nMonth),0)
EOM = Format(EOM,"mm/dd/yyyy")
LastDay = Day(EOM)
LastDayOfMonth = Day(EOM) 'Last Day of Previous Month
END Function
This should get you started.
Walt
>I using Access 2000 and need assistance to get the number of days in a
>month. For example, number of days in December is 31 days.
>
>Thanks,
>Maha
Message #4 by Walt Morgan <wmorgan@s...> on Thu, 13 Dec 2001 11:32:39 -0600
|
|
Gerald,
Always like to learn a new way to do old things! Thanks for sharing.
Walt
Message #5 by "Gerald, Rand" <RGerald@u...> on Thu, 13 Dec 2001 16:01:53 -0600
|
|
For more information check the following reference in the Microsoft
Knowledge base:
ACC2000: How to Find the Number of Days in a Month (Q210448)
You only need to search for the "Q" number. E.g. Q210448
Rand
Ps: I had originally designed a different routine for doing the same thing,
but I found the Microsoft version to be more elegant (less code)!
-----Original Message-----
From: Walt Morgan [mailto:wmorgan@s...]
Sent: Thursday, December 13, 2001 11:33 AM
To: Access
Subject: [access] Re: Number of days in a Month
Gerald,
Always like to learn a new way to do old things! Thanks for sharing.
Walt
Message #6 by "Maha Arupputhan Pappan" <mahap@p...> on Wed, 19 Dec 2001 05:57:24
|
|
Hi guys,
Thank you very much. I found the trick now. Thanks guys.
|
|
 |