I have the following code to convert a date (from a database entry) into the correct format:
Dim blah As Date = "02/29/2001"
MsgBox(Format(blah, "yyyy-MM-dd"))
However, it keeps telling me this:
Conversion from string “02/29/2001” to type ‘Date’ is not valid.
Now i see that 2/29/2001 does not have a day 29- only 28 for that year. So how would i check for this so it doesn’t throw an error when a date in the database table is not entered correctly?
You can use
IsDate()This function returns true if your string or date can be converted to date.
like this
This will return true for the first one and false for the second one
Also, this function works with month of 29, 30 or 31 days like in your case
here’s the msdn link