ProblemYou want to calculate the number of days in a given month. SolutionUse the shared function DaysInMonth provided by the Date object. This function returns the number of days in a month, given the month and year. DiscussionUnlike the DayOfWeek and DayOfYear properties available on every Date variable, DaysInMonth is a shared function. Instead of prefixing the call with a specific Date, use the generic Date object to access this function. The following code shows the correct syntax as it gets the number of days in the current month: Dim daysInMonth As Integer = _ Date.DaysInMonth(Now.Year, Now.Month) MsgBox(String. Format( _ "Number of days in the current month: {0}", daysInMonth)) Figure 7-17 shows the results as displayed by the message box. Figure 7-17. Determining the number of days in a given month with the shared function DaysInMonth |