How to Convert Date to a String in VB6

By Lysis

Date conversions are common tasks in programming. Converting a date to a string allows you to use string-specific functions on your variables. The Visual Basic (VB) compiler language has prebuilt functions that allow you to convert the date variables to a string. The conversion is accomplished using a function named "Cstr()." Cstr converts any variable to a string format.

Step 1

Create the date variables and assign a value. The third variable is the string variable, which is used for the assignment.Dim myDate as DateDim myString as StringmyDate="12/20/1975"

Step 2

Convert the date to a string and assign the new value to the string variable. The following code converts your date:myString = Cstr(myDate)

Step 3

Print the result to a message box. A message box is used to test the code and verify that the conversion was successful. The following code displays your new string value:MsgBox(myString)

Step 4

Save the changes and click the "F5" key. The F5 key compiles your code and executes it, so you can test the changes.