How to Convert Date to a String in VB6

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
Convert dates to string using Cstr.

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.

Advertisement

Step 1

Create the date variables and assign a value. The third variable is the string variable, which is used for the assignment.

Video of the Day

Dim myDate as Date Dim myString as String myDate="12/20/1975"

Advertisement

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:

Advertisement

Advertisement

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.

Video of the Day

Advertisement

Advertisement

references

Report an Issue

screenshot of the current page

Screenshot loading...