Library code snippets
Displaying a Date
By Super Tal, published on 24 Mar 2002
Many people ask me how I get the day of the week and the full date to display on my web sites, well, it's easy. Simply put the following three lines of code in your ASP page and presto!
var_date=date() 'get the current date
var_date=FormatDateTime(var_date,1)
Response.Write(var_date)
Formating options are:
| VB Constant Name | Value | Description |
vbGeneralDate
|
0
|
Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed. |
vbLongDate
|
1
|
Display a date using the long date format specified in your computer's regional settings. |
vbShortDate
|
2
|
Display a date using the short date format specified in your computer's regional settings. |
vbLongTime
|
3
|
Display a time using the time format specified in your computer's regional settings. |
vbShortTime
|
4
|
Display a time using the 24-hour format (hh:mm). |
Related articles
Related discussion
-
Calling a function from ASP code
by dunk00 (3 replies)
-
GridView HyperLinkField Problem
by Paul2 (0 replies)
-
looking for help on asp
by cladironbeard (2 replies)
-
simple vb to c#, help please
by lksath (1 replies)
-
Binary Studio | software development outsourcing Ukraine
by Hexfinity (2 replies)
Related podcasts
-
Scott Guthrie
Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.
Events coming up
-
Aug
27
Model-View-Presenter (MVC) in ASP.NET
San Francisco, United States
Model-View-Presenter (MVC) in ASP.NET Presenter Clayton Peddy, Terrace Software, Inc. Details TBD
Hello,
How about this statement:
vbShortTime - 4 - Display a time using the 24-hour format (hh:mm).
If I want to Display a short time using the time format specified in your computer's regional settings?
Thank You for suggestions :)
Regardz,
Sledge
You are glad you are not dealing with other languages and computer settings
. This is not your nor mine mistake, but date formats are real madness sometimes. For example Windows API functions (used by VBScript in ASP) are able to generate correct Bulgarian date, but they are unable to parse it back! This happens even in MS Access, Excel etc. E.g. the problem is in the system provided formatting functions. Unfortunately this is not the only problem.
For example this text 12.11.2000 can be parsed as 12 Nov 2000 and as 11 Dec 2000. Most formats using "." as date separator order the components day.month.year. However windows functions are trying to be "intelligent" and if you need an input from the user and your server is set to US localle you can expect many interesting situations. The "." will not cause error but sometimes you will receive a strange date value.
Unending problem! Thus if you need input better set-up some kind of callendar - in a pop-up window, inline to generate the string and read the date manually in the ASP page.
This thread is for discussions of Displaying a Date.