Solved

DateTimePicker - how to validate correctdate against another DTP?

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

22 Experts available now in Live!

Get 1:1 Help Now