Vba cdate function in Excel
The Cdate function Is used to convert a string representation of date into date format.
The date expession must be in any of the excel supported date format, which can be seen from the "Format Cells" dialog box.
The Cdate function has two arguments, and the syntax is as shown below.
The expression is the string containing the date expression
"Long Date", "Short Date" and custome expressions such as "YYYY-DD-MM","MM-DD-YY" are some of the most commonly used.
The Cdate function is very important as most of the date information obtained extrenally from the users are of plain text and
for the excel to identify this as date, it has to be converted.
The following example illustrates this
MsgBox "Long Date " & vbNewLine & Format(CDate("2017/4/23"), "Long Date")
MsgBox "Short Date " & vbNewLine & Format(CDate("2017/4/23"), "Short Date")
MsgBox "Custom Date Format " & vbNewLine & Format(CDate("2017/4/23"), "yyyy-mm-dd")
The screenshot of the editor is as shown below