During my programming I was facing a problem with String to date Conversion. Most of the time I managed to convert the String date to my system default date format "DD/MM/YYYY".
But later on as I'm going to develop projects I'm repeatedly facing problems with this date conversion and searching in the net for a solution. But as this may be a small issue for others I didn't find any proper solution for that. But I tried to build a small function which will convert the user date string to system date. So here I'm posting this code to help my fellow developers.
The code will take date string in "DD/MM/YYYY" format and convert that to a system date.
Code:
Private Function Converttodate(ByVal filedate As String) As Date
Dim sysdateformat As String =
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern
Dim dateseperator As String =
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator
Dim sysdatesplit() As String =
sysdateformat.Split(dateseperator)
Dim filedatesplit() As String =
filedate.Split("/")
Dim file_DD As String =
filedatesplit(0)
Dim file_MM As String =
filedatesplit(1)
Dim file_YY As String =
filedatesplit(2)
Dim filedatenew As String = ""
filedatesplit = Nothing
ReDim filedatesplit(3)
For i As Int16
= 0 To sysdatesplit.Length
- 1
If sysdatesplit(i).ToUpper.Contains("D") Then
Join the conversation! Your thoughts help the community grow.