DatePicker problem in Visual Studio

By jeffreyalejo ·
I updated a few lines of code in my Visual Studio Application which involves the DatePicker tool.

Here is the code:

If dtpReceivedDate.Value < dtpCVDate.Value Then
MsgBox("CV Date is greater than Received Date.", MsgBoxStyle.Information, "Date Error")
Exit Sub
Call SaveCV()
End If

Basically, the program will not save (Call SaveCV) any information if the dtpReceivedDate (DatePicker) is less than dtpCVDate (DatePicker). It works when I tested it in my development machine where Visual Studio is installed. I build the solution and copy the exe file to another PC where the application is deployed and being used.

My problem is this, the condition in the code seems to fail when both the DatePicker has the same value (it displays the Messagebox). It should proceed in the next line of code because the values of the DatePickers are equal.

What could have gone wrong?

Thanks in advance.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

DateTime Issue?

by jgarcia102066 In reply to DatePicker problem in Vis ...

Try this:

1. Set the dtpCVDate to a specific date first and then set the dtpReceivedDate to the same date. Check to see if it processes correctly.

2. Set the depReceivedDate to a specific date first and then set the depCVDate to the same date. Check to see if it processes correctly.

If step 1 processes correctly and step 2 does not, then the issue is that your date pickers are storing the DateTime value with the current time. In this case the first date picker you set will always be less than the second date picker when you set the same date because the of the time.

I have used a few different techniques for dealing with this issue. One of the easiest is to convert the DateTime into an integer represented by YYYYMMDD and compare those values. This removes the time element from the equation.

If there are better ways to deal with the datetime issue, I'd like to see that!!

Related Discussions

Related Forums