VB icon

Calculate the last day of the month

Email
Submitted on: 1/5/2015 5:55:00 AM
By: Mike Collins (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages)
Views: 1596
 
     Determines number of days in a month, with leap year check.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :Calculate the last day of the month
'**************************************
Copyright (c) 2000 Mike Collins.
You are hearby granted the right of non-exclusive use for any reason provided that you provide this copyright message in any work that uses this code.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Calculate the last day of the month
' Description:Determines number of days in a month, with leap year check.
' By: Mike Collins (from psc cd)
'
' Inputs:Month and year requested
'
' Returns:Number of days in that month
'
' Assumes:Nothing
'**************************************

Here is the VBScript Sample
----------------------------------------------
function GetLastDay( month, year )
 month = month + 1
 if month > 12 then
month = month - 12
year = year + 1
 end if
 Dim x
 x = DateAdd("d", -1, month&"/01/"&year)
 GetLastDay = Day( x )
end function
Response.Write GetLastDay( 3, 1999 )&"<br>"
Response.Write GetLastDay( 2, 1999 )&"<br>"
Response.Write GetLastDay( 2, 2000 )&"<br>"
----------------------------------------------
Here is the JavaScript Sample
----------------------------------------------
function GetLastDay( month, year )
{
 month++;
 if( month > 12 )
 {
month -= 12;
year++;
 }
 var x = new Date( month+"/1/"+year );
 x = new Date( x.valueOf()-(1000*60*60*24) );
 //1000*60*60*24=number of millisecs in 1 day
 return x.getDate();
}
Response.Write( GetLastDay( 3, 1999 )+"<br>" );
Response.Write( GetLastDay( 2, 1999 )+"<br>" );
Response.Write( GetLastDay( 2, 2000 )+"<br>" );


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.