Solved

date validation

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

832 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