Validating WebDatePicker Data

I’m pulling DateValue data from a database and setting a WebDatePicker with the value, and it works fine as long as the column has the data as yyyy-mm-dd (which it should be, but it isn’t always because . . . Well, reasons…).

How can I go about testing the data and, if it isn’t valid, fixing it by adding the mm or dd data (which I’m fine being January 1st for any entries that need fixing).

Right now I’m pulling data with this:

self.InventoryDatePicker.Value=InventoryRS.column("PurchaseDate").DateValue

Any help would be appreciated.

I check if InventoryRS.column(“PurchaseDate”).StringValue <> “”, then I try to Parse it (eg “0000/00/00 00:00:00” doesn’t exist, there is no zero month or day). If these fail then put in the default date.

Thank you! I will give it a try this afternoon.

Your solution works, although I feel like I overcomplicated it.

    if inventoryRS.Column("PurchaseDate").StringValue<>"" then
  var SelectedDate as string = inventoryRS.Column("PurchaseDate").StringValue
  var myDate as DateTime
  try
    myDate = DateTime.FromString(SelectedDate)
    MessageBox myDate.ToString
  catch e as RuntimeException
    SelectedDate=SelectedDate+"-01-01"
    myDate = DateTime.FromString(SelectedDate)
    MessageBox myDate.ToString
  end try
  self.InventoryDatePicker.Value=myDate
  
else
  //The date is null-Don't do anything.
  
end if

Feel free to point out how I could simplify that. Thank you again!