vba string to date code example
Example 1: string to date vb
Dim iDate As String = "05/05/2005"
Dim oDate As DateTime = Convert.ToDateTime(iDate)
MsgBox(oDate.Day & " " & oDate.Month & " " & oDate.Year)
Example 2: vba string to date
Dim myDate As Date, strDate As String
myDate = CDate("2021-01-28")
strDate = Format(myDate, "YYYY-MM-DD") ' 2021-01-28
' String to date
myDate = CDate(Format$("20210213101235", "####-##-## ##:##:##"))
' Date to string
strDate = Format(myDate, "YYYY-MM-DD hh:mm:ss") ' 2021-02-13 10:12:35
Example 3: string to date vb
string iDate = "05/05/2005";
DateTime oDate = Convert.ToDateTime(iDate);
MessageBox.Show(oDate.Day + " " + oDate.Month + " " + oDate.Year );