Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Date processing in VB

Posted on 2004-10-27
Medium Priority
Last Modified: 2010-04-17
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...??
Question by:bushairkp
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 10

Expert Comment

ID: 12419971
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
LVL 10

Expert Comment

ID: 12419973
If it's actually a date type, the format doesn't matter
.. Alan

Author Comment

ID: 12422567
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 ...??
LVL 10

Accepted Solution

ADSaunders earned 100 total points
ID: 12422670
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

Expert Comment

ID: 12426573
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.)

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question