Date processing in VB

Given a date in mm/dd/yyyy format. how can i find the no of days on that month.  is there any built in functions available in VB...??
bushairkpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ADSaundersCommented:
Hi bushairkp,
If it is a date type, then the difference in days between that date and a month hence will give you the answer:
Days = datediff("d", <givendate>, dateadd("m",1, <givendate>))

Regards .. Alan
0
ADSaundersCommented:
bushairkp,
If it's actually a date type, the format doesn't matter
.. Alan
0
bushairkpAuthor Commented:
i am telling you ...i want to find the no of days of a month.
i mean ..suppose our function name is xxxxx
if i passed a value to (01/01/2002) then it should return 31 , and if i passed a value 02/15/2002(feb) then it should return 28. if the value is 02/15/2004 (feb-leap year) it should return 29.....

do you know any functions intented for that ...??
0
ADSaundersCommented:
Hi,
The above statement will do that.
Given 01/01/2002 as <givendate>:
dim Givendate as date, NextMonth as date
Givendate = cDate("01/01/2002")
NextMonth = dateadd("m",1, Givendate) will give a date that will format as either 01/02/2002 or 02/01/2002 (depending on US or GB locale)
datediff("d",Givendate,NextMonth) (GB) will give the number of days between 01/01/2002 and 02/01/2002. i.e. the number of days in January 2002.

.. Alan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rick_TownsendCommented:
Here's an alternative (if you're looking for other options.)  The following code uses the DateSerial function:

    Format$(Day(DateSerial(Year(givenDate), month(givenDate) + 1, 0)))

(It assumes that givenDate is a Date type.  Use cDate(dateString) as specified by ADSaunders if you need to do a String to Date conversion.)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.