codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:

Home » ASP » Article

ASP Format Date and Time Script

Article by:  Jeff Anderson  ( 1362 ) (2/27/2002)
Bookmark us now! Add to Favourites
Email a friend! Tell a friend
Summary: An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
Viewed: 766620 times Rating (221 votes): 
 4.3 out of 5
  Rate this Article   Read Comments   Post Comments


ASP has a very handy inbuild function called FormatDateTime().

Let's start with the now() function to get the current date and time into a variable


<% 
dim todaysDate
 todaysDate=now()
 
%>


Now we can use the FormatDateTime function to format our date variable in a variety of ways.

First let's see how todaysDate appears :


<% 
Response.write todaysDate
 
%>


RESULT: 2/6/2015 2:09:13 AM

Using 0 - the vbGeneralDate format creates a date as short date (if included), and time as long time.




<% 
Response.write FormatDateTime(todaysDate,0)

 
%>


RESULT: 2/6/2015 2:09:13 AM

Using 1 - the vbLongDate shows the date as long date




<% 
Response.write FormatDateTime(todaysDate,1)

 
%>


RESULT: Friday, February 06, 2015


Using 2 - the vbShortDate shows the date as short date




<% 
Response.write FormatDateTime(todaysDate,2)

 
%>


RESULT: 2/6/2015


Using 3 - the vbLongTime format shows the time as long time .




<% 
Response.write FormatDateTime(todaysDate,3)

%>


RESULT: 2:09:13 AM


Using 4 - the vbShortTime format creates the current time in 24 format (hh:mm)




<%
Response.write FormatDateTime(todaysDate,4)

 
%>


RESULT: 02:09




International Date and Time

You can use the session.lcid property to change the formatting of the date and time.

For example
<%session.lcid=2057%>
will set the date and time to UK format (DD/MM/YYYY instead of MM/DD/YYYY ) Here's a list of international locales. Bear in mind that setting these will also change currency formatting.

Locale ID (LCID) Description
1033 General Unicode
33280 Binary Order
1027 Catalan
197636 Chinese Bopomofo (Taiwan)
2052 Chinese Punctuation
133124 Chinese Stroke Count
1028 Chinese Stroke Count (Taiwan)
1050 Croatian
1029 Czech
1043 Dutch
1061 Estonian
1036 French
66615 Georgian Modern
1031 German
66567 German Phone Book
1038 Hungarian
66574 Hungarian Technical
1039 Icelandic
1040 Italian
1041 Japanese
66577 Japanese Unicode
1042 Korean
66578 Korean Unicode
1062 Latvian
1063 Lithuanian
1071 FYRO Macedonian
1044 Norwegian/Danish
1045 Polish
1046 Portuguese
1048 Romanian
1051 Slovak
1060 Slovenian
1034 Spanish (Traditional)
3082 Spanish (Spain)
1053 Swedish/Finnish
1054 Thai
2057 UK English
1058 Ukrainian
1066 Vietnamese



Adding and Subtracting Dates and Times

For more information about adding and subtracting dates and times, see our ASP DateAdd article.




Useful Links


CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'ASP Format Date and Time Script'
RELATED ARTICLES
ASP FilesystemObject
by Jeff Anderson
An introduction to the Filesystemobject
ASP GetTempName
by Jeff Anderson
Use the GetTempName method to create a randomly generated temporary file on the server.
ASP Format Date and Time Script
by Jeff Anderson
An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
ASP OpenTextFile
by Jeff Anderson
An introduction to the OpenTextFile Method of the FileSystemObject
Email validation using Regular Expression
by Jeff Anderson
Using regular expression syntax is an exellent way to thoroughly validate an email. It's possible in ASP.
Add or Subtract Hours in SQL or ASP using DateAdd
by Jeff Anderson
A beginners guide to using the SQL DATEADD function to add or subtract hours. Particularly useful when setting the time displayed on the ASP page to a different time zone (eg when the server is in the US, and the site is for a UK audience).
The asp:radiobutton and asp:radiobuttonlist control
by David Sussman, et al
In HTML, radio buttons are used when we need to make multiple sets of choices available, but we want the user to select only one of them.
The asp:checkbox and asp:checkboxlist control
by David Sussman, et al
Checkboxes are similar to radio buttons, and in HTML, they were used to allow multiple choices from a group of buttons.
ASP FileExists
by Jeff Anderson
An introduction to the FileExistsMethod of the FileSystemObject
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).








Recent Forum Threads
•  Run a program both on windows and linux
•  VERO.SurfCAM.v2014
•  Schlumberger.Petrel.V2013.2
•  Petrel.V2013.2
•  Altair.HyperWorks.v12
•  VoluMill.v6.1
•  VoluMill.NEXION.6
•  VERO.SurfCAM.v2014
•  Schlumberger.Petrel.V2013.2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2015