SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Display of date and time in local format in ASP using FormatDateTime

We can display Formatted date and time by using FormatDateTime function of VBScript within ASP. This function can take only date , only time or both date and time and display in specified format. Here is the format the function FormatDateTime uses.

FormatDateTime(my_date,Format)


Here my_date is the date variable and Format takes the value of 0 to 4 and format the display based on this. The table at the end of this page displays all possible formats with different value of Format.

Here is the code to use FromatDateTime function.

Dim my_date,var_Locale
var_Locale = SetLocale(1033)
my_date=Now
Response.Write FormatDateTime(my_date,0)


Here the Format value is specified as 0 so the output of this is here .

7/19/2006 8:38:39 PM


For different values of Format ( 0 to 4 ) Here is a table of displays. Note that SetLocale is set to USA format. For other list of LCID value of local formats please see the article on today date and time.
FormatDisplayTypeDetails
0vbGeneralDate7/19/2006 8:38:39 PM Date and Time
1vbLongDateWednesday, July 19, 2006Date in Long format
2vbShortDate7/19/2006Date in m/d/yyyy
3vbLongTime9:53:22 PMLong Time
4vbShortTime15:53Short Date


There is a list of LCID values for SetLocale for different countries listed at Microsoft site.

Further readings
Getting todays Date and Time based on local settings
Formatting date and time on local settings
Adding Date intervals using DateAdd function
Finding difference between two dates using DateDiff function
Collecting parts of Date by using DatePart function
Collecting Month name by using Month number by MonthName function
Collecting Name of the weekday of any Date by WeekDayName function
Generating Date variables by using Month, Day and Year Value
Function IsDate to check valid date or date variable
Checking user entered date value
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.