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:


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
    myDate = DateTime.FromString(SelectedDate)
    MessageBox myDate.ToString
  catch e as RuntimeException
    myDate = DateTime.FromString(SelectedDate)
    MessageBox myDate.ToString
  end try
  //The date is null-Don't do anything.
end if

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

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.