Is there a method in VB if I pass in a month and year it will tell me the number of days in the month?
Printable View
Is there a method in VB if I pass in a month and year it will tell me the number of days in the month?
Well I have a vague idea that it can be done using the calendar property.
Declare a variable as calendar and then try.I hope you can find your way out!!!
You need to look at the 'DateDiff' function in VB (in the help). Here's a quick example :
Dim dteStartDate as date
Dim dteEndDate as date
dteStartDate = CDate("01 Feb 1999") ' could use #2/1/1999
dteEndDate = CDate("01 Mar 1999") ' could use #3/1/1999
MsgBox DateDiff("d", dteStartDate, dteEndDate)
This shows the number of days between the two dates (and hence in the month).
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
A simple way to implement this is to move to the 1st of the next month and -1 a day to find the max nos of days this month using the dateadd function.
Ex : =
curr_dt = '1/9/99'
last_DATE = DateAdd("D", -1, (DateAdd("M", 1, curr_dt)))