• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Need some quick and easy code to validate a date range

I have two text boxes on a form that a user enters dates in.

t_start_date
t_end_date

I would like some code to check that the range entered is valid.  In other words, that then t_end_date does not occur before the t_start_date.

1/1/2011  and 12/31/2011  - Good

1/1/2011 and 12/31/2010  - no good
0
snyperj
Asked:
snyperj
  • 2
1 Solution
 
skrgaCommented:
Something like:
If FormatDateTime(DATE1, vbShortDate) < FormatDateTime(DATE2, vbShortDate) = True Then
MsgBox ("Please enter a valid date.")
txtDate.SetFocus

Open in new window

0
 
skrgaCommented:
Above code works only for year and day (not month),
try code below:

If DateDiff("s", Date1, Date2) < 0 Then
'Date1 is later than Date2
Else
'Date2 is later than Date1
End If

Open in new window


0
 
snyperjAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now