devxlogo

Format a Date as mm/dd/yyyy

Question:
I need a VBScript function that will format a date as mm/dd/yyyy. The FormatDateTime function does not give me this option and the CDate function wants to convert everything into mm/dd/yy. How can I do this?

Answer:

You can do this one of two ways. First, you can set the Short Date settings on your server to mm/dd/yyyy. Then call FormatDateTime passing the argument vbShortDate. (Remember, vbShortDate = 2).

Second, you can write your own function to parse out a date and return it as mm/dd/yyyy. You can use the DatePart function to obtain the month, day, and year, and then put them together, ensuring that the format is in the way you want it.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

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.