Solved

date validation

Posted on 1998-06-09
2
204 Views
Last Modified: 2010-05-03
dear sir,

l'm doing the date validation programming, for example, if todays is april 98, then how do l know that this month is got 30,31 or just 28 days ?
0
Comment
Question by:e_aks
[X]
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
2 Comments
 

Accepted Solution

by:
SergeD earned 30 total points
ID: 1462869
Hi,

there is no special function which returns the number of days in the month. But you can easily make a loop until the date pass to the next month.

Private Function NbDays(ByVal iMonth As Integer, _
                                     ByVal iYear As Integer) As Integer
Dim i As Integer
Dim MyDate As Date

MyDate = CDate("28/" & Format(iMonth) & "/" & Format(iYear))

' Loop for the 29, 30 and 31
For i = 1 To 4
    If Val(Format(MyDate, "mm")) > iMonth Then
        NbDays = 26 + i
        Exit Function
    End If
    MyDate = MyDate + 1
Next i

NbDays = 31

End Function

0
 
LVL 1

Expert Comment

by:mmahdi
ID: 1462870
e_aks,

You can use the following function as a General Procedure:

Public Function LastOfMonth(Optional vdatBase As Variant, Optional viOffset As Variant) As Date

       Dim datBase As Date
       Dim iOffset As Integer

              If Not IsMissing(vdatBase) Then
                      datBase = CDate(vdatBase)
              Else
                      datBase = Date
              End If


              If Not IsMissing(viOffset) Then
                      iOffset = CInt(viOffset)
              Else
                      iOffset = 0
              End If

       LastOfMonth = DateSerial(Year(datBase), Month(datBase) + iOffset + 1, 0)
End Function

to get the last day of each month try:

msgbox LastOfMonth(now) 'will return "30 June 1998"

Regards
mmahdi
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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