Functions for formatting time and dates under ASP

Source: Internet
Author: User
Tags date format functions string
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

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.