Solved

DateTimePicker - how to validate correctdate against another DTP?

Posted on 2004-10-17
6
325 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
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 250 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

19 Experts available now in Live!

Get 1:1 Help Now