Solved

date validation

Posted on 1998-06-09
2
198 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

713 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