Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Vb.Net - Compare Dates

Posted on 2013-05-16
9
Medium Priority
?
328 Views
Last Modified: 2013-05-16
Good Day Experts!

I have two textboxes that accept start and end dates.  I have a routine that checks if the dates are formatted in acceptable formats.  That part works great.  The last step of the routine I want to check if the start date is less than the end date.  However, I am apparently doing something wrong since 1/1/2103 is not flagged as greater than 5/17/2013.  Here is my compare:

If txtStartPW.Text.Trim > txtEndPW.Text.Trim Then
   ValidationResult = "Start Date is not less than End Date. Please revise your entry."
End If

It "feels" like it is going to be something related to the values being strings and not comparing the actual dates...but, I am not good with coding around date stuff.

Can you help?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[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
9 Comments
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39171346
Hi,

What are the valid formats? Is it only M/D/YYYY?

Giannis
0
 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 1200 total points
ID: 39171351
If CDate(txtStartPW.Text.Trim)CDate(txtEndPW.Text.Trim) Then
   ValidationResult = "Start Date is not less than End Date. Please revise your entry."
End If


...or something to that affect.
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 39171357
Yes, do as above because as strings 1/1/2103 is less than 5/17/2013.
0
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!

 

Author Comment

by:Jimbo99999
ID: 39171358
"M/d/yyyy", "MM/dd/yyyy", "M/dd/yyyy", "MM/d/yyyy"
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 600 total points
ID: 39171364
If DateTime.Parse(txtStartPW.Text.Trim) > DateTime.Parse(txtEndPW.Text.Trim) Then
   ValidationResult = "Start Date is not less than End Date. Please revise your entry."
End If

Open in new window

0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 100 total points
ID: 39171373
why reinvent the wheel. You should use the DateTimePicker control to input dates. When comes time to compare, as already mentioned, you need to compare dates and not text.
0
 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 100 total points
ID: 39171387
Add :
Imports System.Globalization

Open in new window

and try this:
MsgBox(DateTime.ParseExact("5/17/2013", "M/d/yyyy", a) > DateTime.ParseExact("1/1/2103", "M/d/yyyy", a))

Open in new window


Giannis
0
 

Author Comment

by:Jimbo99999
ID: 39171398
We actually did consider that. But, after polling the User community they voted on manual entry.  Most of them were former Data-entry people so they are pretty quick on the number keypad.
0
 

Author Closing Comment

by:Jimbo99999
ID: 39171417
Thanks everyone for your responses.  In my spare time I will try out the DateTimePicker control for future reference.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

671 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