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
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
-
ASP VS PHP
by paulfp (9 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
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.