Function to get date in Month/Day/Year format.

Virendradugar
Posted by Virendradugar under VB.NET category on | Views : 3681

Public Shared Function GetDateFormat(ByVal strDate As String) As DateTime
Dim day As String = ""
Dim month As String = ""
Dim year As String = ""
If (strDate.IndexOf("/") > 0) Then
day = strDate.Substring(0, strDate.IndexOf("/"))
month = strDate.Substring(strDate.IndexOf("/") + 1, 2)
year = strDate.Substring(strDate.LastIndexOf("/") + 1)
ElseIf (strDate.IndexOf("-") > 0) Then
day = strDate.Substring(0, strDate.IndexOf("-"))
month = strDate.Substring(strDate.IndexOf("-") + 1, 2)
year = strDate.Substring(strDate.LastIndexOf("-") + 1)
Else
day = strDate.Substring(0, 2)
month = strDate.Substring(2, 4)
year = strDate.Substring(4)
End If
Dim ReturnDate As DateTime
Dim strdt = month + "/" + day + "/" + year
ReturnDate = Convert.ToDateTime(strdt)
Return ReturnDate
End Function

Comments or Responses

Login to post response