Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# date validation

Posted on 1998-06-09
Medium Priority
210 Views
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
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

Accepted Solution

SergeD earned 90 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

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

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
###### Suggested Courses
Course of the Month11 days, 2 hours left to enroll