ASP Date format Problem _ Application Tips

Source: Internet
Author: User
Tags locale access database

For dates that are stored in the date-time Type field of an Access database, the effect that is read directly from the database is shown with time, such as, 2009-06-13 18:00, what if just want to show the date?
Vbscrip has a function formatdatetime (). The notes are as follows:
Returns an expression that has been formatted as a date or time.
FormatDateTime (date[, NamedFormat])
Parameters
Date
Required option. The date expression to be formatted.
NamedFormat
Options available. Indicates the value of the date/time format used, and if omitted, uses Vbgeneraldate.
Set up
The NamedFormat parameter can have the following values:

Constant

Value

Describe

Vbgeneraldate

0

Displays the date and/or time. If there is a date part, the section is displayed as a short date format. If there is a time section, the section is displayed in a long time format. If all exist, all parts are displayed.

vbLongDate

1

Displays a date using the long date format specified in the computer's regional settings.

Vbshortdate

2

Displays a date using the short date format specified in the computer locale.

Vblongtime

3

Displays the time using the time format specified in the computer locale.

vbShortTime

4

Displays the time using the 24-hour format (hh:mm).

The

only wants to display the date with the following code:
Strdate=formatdatetime (rs ("date"), 2).
because there is only one area of the computer in VBScript that is the United States, so there is only one short format
"Yyyy-mm-dd".

ASP Time Date formatted output
1,2010-10-10 00:00:00
2,2010-10-10
3,2010/10/10
4, October 2010 10 0 0 hours 00 minutes 00 seconds
5,10-10 00:00:00
6,10/10
7, October 10
Other transformations are added by program

' Convert time format Function formatdate (Byval t,byval ftype) Dim y, M, D, H, MI, S formatdate= "" If IsDate (t) =false Then Exit  Function Y=cstr (Year (t)) M=cstr (month (t)) if Len (m) =1 Then m= "0" & M d=cstr (Day (t)) if Len (d) =1 Then d= "0" & D h = CStr (hour (t)) if Len (h) =1 Then h= "0" & H mi = CStr (minute (t)) if Len (mi) =1 Then mi= "0" & mi s = CStr (s Econd (t) If Len (s) =1 Then s= "0" & S Select Case CInt (ftype) Case 1 ' yyyy-mm-dd formatdate=y & "-" & M & Amp "-" & D Case 2 ' Yy-mm-dd formatdate=right (y,2) & "-" & M & "-" & D Case 3 ' Mm-dd formatdate=m  & "-" & D Case 4 ' Yyyy-mm-dd hh:mm:ss formatdate=y & "-" & M & "-" & D & "" & H & ":" & Mi & ":" & S Case 5 ' Hh:mm:ss formatdate=h & ":" & Mi & ":" & S Case 6 ' yyyy year mm month 
DD Day Formatdate=y & "Year" & M & "Month" & D & "Day" Case 7 ' YYYYMMDD Formatdate=y & M & D case 8 ' Yyyymmddhhmmss FOrmatdate=y & M & D & H & mi & S End Select End Function 
 

How to use:

Strdate=formatdatetime (RS ("date"), 1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.