Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi How to check given value or string is datetime or not in vb.
E.g:User can give value like this 100-10-6-1,actually "100-10-6-1" is serial no,so how to check this is datetime or not in asp.net using vb.

VB
'Below all not working correctly

 Dim value1 As String = "100-10-6-1"
 Dim inta As DateTime
 If (Not DateTime.TryParse(value1, inta)) Then
 ShowMessage("This is not date field !")
 Exit Sub
 End If
'--------------------------------------
  Dim value1 As String = "100-10-6-1" 'Here if give "11-11-11" also goes else part
 If stringSplit(inti).[GetType]() Is GetType(DateTime) Then
  ShowMessage("This is  date field !")
  Else
  ShowMessage("This is not date field !")
 End If


What I have tried:

http://stackoverflow.com/questions/3998685/how-to-determine-if-an-object-is-a-datetime-in-vb-net

I try this link ,but it show error
http://prntscr.com/a4rwsk




Regards
Aravind
Posted
Updated 17-Feb-16 22:36pm

1 solution

The Stack Overflow solution doesn't work for you, because your data type is anyway a string. You should establish if such a string is a valid representation of a DataTime value. Fopr the purpose you may use either the DateTime.TryParse Method (System)[^] or DateTime.TryParseExact Method (System)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900