Solved

date validation

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now