Solved

DateTimePicker - how to validate correctdate against another DTP?

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
how to remove error in database 6 55
"lblTime is not declared" 3 65
VB.net VSTO Excel Ribbon error 4 28
VB Catch Statement in Event Viewer. 2 20
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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