Skip navigation

Generate Dates in the Format You Want in Your VBScript and T-SQL Code

Systems administrators often need to include dates and times in file and folder names. Although VBScript has functions to retrieve and format dates and times, they're formatted according to the locale and they usually include characters that you can't use in filenames, such as forward slashes and colons.

Following the format outlined in the ISO 8601 standard is a better choice when you need to include dates and times in file and folder names. In "Creating Date and Time Stamps," Alex K. Angelopoulos explains why following this format is advantageous, and he shows you how to easily generate ISO 8601 stamps in VBScript code.

I've opened up this article for public viewing so that you can read this article and download its code. The article will be open for public viewing only through August 24, so don't delay. If you enjoy reading this article, you can get more of this type of content by subscribing to Scripting Pro VIP.

Like systems administrators, database administrators often need to generate dates in different formats. Although you can obtain the current date with T-SQL's GETDATE function, getting the returned date in the format you need can take a lot of effort and code.

Roy Byrd was tired of having to write custom code every time he needed a date in a different format, so he wrote the FormatDate function. You can use this function to display any date in the format you need. All you need to do is provide two parameters. If you'd like to read more about FormatDate and download its code, look for the article "Display Dates in the Format You Need" in the September issue of SQL Server Magazine. The article will be available online starting August 23. Starting on August 23, go to the SQL Server Magazine Web site, enter 96608 in the InstantDoc ID box, and click Go.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish