NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Formatting Dates

Written by Eric Smith, Northstar Computer Systems LLC

One quirk about VBScript is that it doesn't include a particularly good format function, like the one included with Visual Basic. For instance, when you format dates, all you have to use is FormatDateTime, which has these four formats:
vbGeneralDate	0	Default – VBScript will show a date and/or time, using the short date and long time formats.
vbLongDate	1	Show the date in the long format defined in your Regional Settings applet
vbShortDate	2	Show the date in the short format defined in your Regional Settings applet
vbLongTime	3	Show the time in the long format defined in your Regional Settings applet
vbShortTime	4	Show the time in the short format defined in your Regional Settings applet
The problem with this is that you can't get a format like MM/DD/YYYY with any of these, by default. You can create your own formatting, however, as shown in this function.
Function Year2000Format(datInput)
   Year2000Format = Month(datInput) & "/" _
      & Day(datInput) & "/" _
      & Year(datInput)
End Function
This will return June 19, 1970 as 6/19/1970, which shows four digits in the year properly. If you need a leading zero, check the length of the value returned from the Month and Day functions and prepend a zero if the length is one.

Keywords: [ Uncategorized ASP Tips ]

Publication Date: 7/1/1999