The keyword Now will return the current date and time. Alternatively, you can use the Date and Time functions, respectively. VBScript has a bunch of handy date handling functions that we can use here.
Code:
Dim dteCurrDate, dteCurrTime
Dim strOutput
dteCurrDate = Date
dteCurrTime = Time
strOutput = Right(CStr(Year(dteCurrDate)), 2) & _
CStr(Month(dteCurrDate)) & _
CStr(Hour(dteCurrTime)) & _
CStr(Minute(dteCurrTime))
Response.Write(strOutput)
The way I do it is via a function I call prefixZero(...).
Code:
Dim dteCurrDate, dteCurrTime
Dim strOutput
dteCurrDate = Date
dteCurrTime = Time
Public Function PrefixZero(num)
Dim newNum
If (CInt(num) < 10)
PrefixZero = "0" & num
Else
PrefixZero = num
End If
End Function
strOutput = Right(CStr(Year(dteCurrDate)), 2) & _
PrefixZero(CStr(Month(dteCurrDate))) & _
PrefixZero(CStr(Hour(dteCurrTime))) & _
PrefixZero(CStr(Minute(dteCurrTime)))
Response.Write(strOutput)
Bookmarks