ASP: Get Last Day Of The Month
Introduction
Author: Martin WarningYear: 2007
License: Free
When working with dates you sometimes need to know what the last day of the month is. This is fairly straightforward as months 1, 3, 5, 7, 8, 10, 12 have 31 days and months 4, 6, 9, 11 have 30 days. Only febuary is a little bit more complex as every 4 years during a leap year it has 29 days instead of 28.
This function will calculate the last day of any given month and year. For February the rule is that if you can divide the year by 4 it's a leap year unless it's a century year. A century year that you can divide by 400 is a leap year as well. The other century years like 1900 are not a leap year.
Code
Languages:- ASP
- VBScript
<% ' Function to get last day of the month ' Requires to have the month number and year passed to the function Function fncLastDay(intMonth,intYear) Dim intDay Select Case intMonth Case 1, 3, 5, 7, 8, 10, 12 intDay = 31 Case 4, 6, 9, 11 intDay = 30 Case 2 If intYear mod 4 = 0 Then If intYear mod 100 = 0 AND intYear mod 400 <> 0 Then intDay = 28 Else intDay = 29 End If Else intDay = 28 End If End Select fncLastDay = intDay End Function %>
