Training
Module
Get Started with Dates, Times, and Time Zones - Training
Learn how to handle date and time effectively in C# applications.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The following code example sets a Boolean
value that indicates whether a string represents a valid date or time.
Dim isValidDate As Boolean = IsDate("01/01/03")
Dim isValidTime As Boolean = IsDate("9:30 PM")
Replace ("01/01/03")
and "9:30 PM"
with the date and time you want to validate. You can replace the string with another hard-coded string, with a String
variable, or with a method that returns a string, such as InputBox
.
Use this method to validate the string before trying to convert the String
to a DateTime
variable. By checking the date or time first, you can avoid generating an exception at run time.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Module
Get Started with Dates, Times, and Time Zones - Training
Learn how to handle date and time effectively in C# applications.