How to: Validate Strings That Represent Dates or Times (Visual Basic)
The following code example sets a Boolean
value that indicates whether a string represents a valid date or time.
Example
Dim isValidDate As Boolean = IsDate("01/01/03")
Dim isValidTime As Boolean = IsDate("9:30 PM")
Compile the code
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
.
Robust Programming
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.
See also
Bendradarbiaukite su mumis dirbdami „GitHub“
Šio turinio šaltinį galima rasti „GitHub“, kur taip pat galite kurti ir peržiūrėti problemas bei teikti užklausas. Daugiau informacijos žr. mūsų bendraautorių vadove.
Atsiliepimai
https://aka.ms/ContentUserFeedback.
Jau greitai: 2024 m. palaipsniui atsisakysime „GitHub“ problemų, kaip turiniui taikomo atsiliepimų mechanizmo, ir pakeisime jį nauja atsiliepimų sistema. Daugiau informacijos žr.Pateikti ir peržiūrėti atsiliepimą, skirtą