[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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...??
0
bushairkp
Asked:
bushairkp
  • 3
1 Solution
 
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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now