Click to See Complete Forum and Search --> : Dates


kjelden
August 19th, 1999, 11:33 AM
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?

August 26th, 1999, 01:24 PM
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!!!

Chris Eastwood
August 26th, 1999, 03:59 PM
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

nilch
August 30th, 1999, 03:01 AM
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)))