?
Solved

DateTimePicker - how to validate correctdate against another DTP?

Posted on 2004-10-17
6
Medium Priority
?
330 Views
Last Modified: 2011-08-18
I have 2 DateTimePickers.

The scenario is similar to checking out a library book.  You first have a date you checked OUT the item, and a date you checked it back IN.
I want to make certain that the user enters a "Date checked back in" date that is later that the original "Date checked out".  No matter what code I try it will not work.  Here is the code as it stands now:

    Private Sub dtpDateIn_validating(ByVal eventsender As Object, ByVal e As System.EventArgs) Handles dtpDateIn.ValueChanged
        If Val(dtpDateIn.Text) < Val(dtpDateOut.Text) Then
            MessageBox.Show("Date In must be later than Date Out")
            dtpDateIn.Focus()
        End If
    End Sub

Any Suggestions?  Been at it for hours.
0
Comment
Question by:veigea41
[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
  • Learn & ask questions
6 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 12335512
I use


    Private Sub dtDateOut_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtDateOut.Leave
        If CType(Me.dtDateIn.Text, Date) > CType(Me.dtDateOut.Text, Date) Then
            MsgBox("Please ensure the date out is after the date in", MsgBoxStyle.Information)
        End If
    End Sub

DAve
0
 
LVL 1

Accepted Solution

by:
surajpant earned 1000 total points
ID: 12336971
check out for datediff function .
first arg may be hour,min, second  . and this will return 0 if the values are same and negative if the second date is greater then the first one.
syntax is given below........

DateDiff(DateInterval.Hour, DateTimePicker1.Value, _ DateTimePicker2.Value))
0
 
LVL 1

Assisted Solution

by:ndonhauser
ndonhauser earned 1000 total points
ID: 12340854
Private Sub dtpDateIn_validating(ByVal eventsender As Object, ByVal e As System.EventArgs) Handles dtpDateIn.ValueChanged
       If dtpDateIn.Value < dtpDateOut.Value Then
            MessageBox.Show("Date In must be later than Date Out")
            dtpDateIn.Focus()
        End If
End Sub
0
 

Author Comment

by:veigea41
ID: 12343765
ndonhauser, surajpant:

 You have solved my problem. This is the code that works with my program.  Thank you.

What I had done wrong is I had been saying dtpDateIn.TEXT.


Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

719 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