Code of the automatic zero-padding function for ASP to read a single date

Source: Internet
Author: User

Copy codeThe Code is as follows: public function fillzero (l1)
If len (l1) = 1 then
Fillzero = "0" & l1
Else
Fillzero = l1
End if
End function

Usage example:Copy codeThe Code is as follows: response year (now) & month (now) & day (now) Result: 201116
Response year (now) & fillzero (month (now) & fillzero (day (now) display result: 20110106

How to control the display of long and short date formats:

Short Date: FORMATDATETIME (DATE, vb1_date)
Long Date: FORMATDATETIME (DATE, vbLongDate)

When the display date is set based on the UK (US) region, the date is displayed in the following format:

Short Date: 7/9/97
Long Date: Wednesday, July 09,1997

Note: The short date format is displayed exactly the same as that without any formatting. By default, dates are displayed in the short date format.

How to Use the FORMATDATETIME () function to operate the time:

Short Time: FORMATDATETIME (TIME, vb1_time)
Long Time: FORMATDATETIME (TIME, vbLongTime)

When the display time is set in the UK (US) region, the time format is as follows:

Short Time: 03: 20
Long Time: 3: 20: 08 AMCopy codeThe Code is as follows: <%
Function FillZero (str)
Ttt = str
If len (str) = 1 then
Ttt = "0" & str
End if
FillZero = ttt
End function
'Conversion date, add one digit to zero--1-2 -->
Function ConvertDate (tDate)
Ttt = tDate
If isdate (tDate) then
Ttt = year (tDate) & "-" & FillZero (month (tDate) & "-" & FillZero (day (tDate ))
End if
ConvertDate = ttt
End function
'Enter a date and time string and convert it to the four-digit adult, and the other two new date and time strings.
Function ConvertDateTime (tDateTime)
Ttt = tDateTime
If isdate (tDateTime) then
Ttt = year (tDateTime) & "-" & FillZero (month (tDateTime) & "-" & FillZero (day (tDateTime )) & "" & FillZero (cstr (hour (tDateTime) & ":" & FillZero (cstr (minute (tDateTime )))&": "& FillZero (cstr (second (tDateTime )))
End if
ConvertDateTime = ttt
End function
%>

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.