devxlogo

Converting a System Date to a Text String

Converting a System Date to a Text String

Question:

I want to retrieve the system date and convert it to a text string. I can get the system date (using the Date() function call), but I cannot write the date to a text file (using the WriteLine method from a TextStream object) unless it is in a string format. The VB Format$() function does not work in the scripting version of VB. Do you have any suggestions?

Answer:

The Format$() function of VB has been replaced by a set of new Format, functions in VBScript.

Use the FormatDateTime function to format a date.

var = FormatDateTime(Date[,NamedFormat])where NamedFormat = 0 - General Date1 - Long Date2 - Short Date3 - Long Time4 - Short Time
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist