WD: How to Determine the Number of Days in a Specified MonthLast reviewed: July 30, 1997Article ID: Q105536 |
The information in this article applies to:
SUMMARYTo determine the number of days in a specified month, use the following Microsoft WordBasic macro Select Case structure. WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Sub Main 'This macro determines the number of days in a given month. datev = DateValue(InputBox$("Enter a date in the mm/dd/yy format")) mon = Month(datev) Select Case mon Case 1, 3, 5, 7, 8, 10, 12 MsgBox "31 days" Case 4, 6, 9, 11 MsgBox "30 days" Case 2 mon = Month(datev) If Year(datev) Mod 4 = 0 Then MsgBox "There are 29 days in this month" Else MsgBox "There are 28 days in this month" End if End Select End SubThis macro prompts for a date in the mm/dd/yy format and returns the number of days in the specified month. The Month function is used to determine the month number for the specified date. Then depending on the month number (1-12), a message box posts the number of days in the month. The macro takes leap years into consideration when computing the number of days in the month of February.
If Year(datev) Mod 4 = 0 ThenThe year is divided by 4 and if the remainder is 0, the number of days in the month is 29 days.
|
Additional query words: month day datevalue
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |