Functions for formatting time and dates under ASP

Source: Internet
Author: User
Tags date format functions
Functions | We sometimes encounter the date format may be 2004-1-12, the system automatically removed the month of 0, but sometimes we need the full date format, such as: 2004-01-12 so what to do? Some of the following functions can be easily handled.

' Put one digit in front of 0

function Fillzero (str)
Ttt=str
If Len (str) =1 Then
ttt= "0" & Str
End If
Fillzero=ttt
End Function

' Conversion date, will be a complement to zero 2003-1-2--> 2003-01-02

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-time string to convert the adult four-bit, the other two-bit new date-time string

function Convertdatetime (tdatetime)
Ttt=tdatetime
If IsDate (tdatetime) Then
Ttt=year (tdatetime) & "-" & Fillzero (Month (tdatetime)) & "-" & Fillzero (Day (tdatetime)) & "" & Fi Llzero (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.