john doe
john doe

Reputation: 9660

How to check if the user enters the default datetime?

I have two textboxes on the screen. They are used for startdate and enddate. If the user does not enter anything in the textboxes I pass nothing (VB.NET) to the webservice. When the webservice receive it on the other end it shows the value "#12:00:00 AM" which I think is the default for the datetime field. Anyway, now I do not want to pass this value to Stored procedure since it will not work. How can I check before sending values to sproc that the value is not the default datetime.

Upvotes: 2

Views: 3586

Answers (3)

Viv
Viv

Reputation: 2595

Instead of DateTime use Nullable of DateTime. Then you can pass a null (or nothing) value to the web service and you use Date.HasValue to check if a value was entered/passed.

Upvotes: 0

Corin
Corin

Reputation: 2457

I can think of two options here.

  1. Since you already know that you're receiving "#12:00:00AM" when the field is not filled in, check if the value you receive is "#12:00:00AM".

  2. Prior to passing the value to your stored procedure, create a new DateTime object. Compare the value you're receiving against the value in the new DateTime object.

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460138

If you don't want to pass it to the WebService, why do you pass it anyway?

To see if a Date is not the "default-date":

If Not Date.MinValue = MyDate

Upvotes: 2

Related Questions