Solved

DateTimePicker - how to validate correctdate against another DTP?

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

631 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