Most programming features are based on the date and time function, such as scheduler and log recoder and monitor etc. We must have ability to familiar with all regular operation of data and time .
We can get date with speific string format from date() function
'Description:
' Function to get current date and time from now function.
'Input:
' None.
'Output:
' currentDate: the current date with string format eg. 20000101
' currentTime: the current time with string format eg. 010101
'Throw Exception When:
' None
currentDate = ""
currentTime = ""
Call toString_Now(currentDate, currentTime)
public function toString_Now(currentDateStr, currentTimeStr)
on error resume next
set nowObj= Now()
yearStr = Cstr(Year(nowObj))
monthStr = Cstr(Month(nowObj))
dayStr = Cstr(Day(nowObj))
if Len(monthStr) = 1 then
monthStr = "0" & monthStr
end if
if Len(dayStr) = 1 then
dayStr = "0" & dayStr
end if
hourStr = Cstr(Hour(nowObj))
minuteStr = Cstr(Minute(nowObj))
secondStr = Cstr(Second(nowObj))
if Len(hourStr) = 1 then
hourStr = "0" & hourStr
end if
if Len(minuteStr) = 1 then
minuteStr = "0" & minuteStr
end if
if Len(secondStr) = 1 then
secondStr = "0" & secondStr
end if
currentDate = yearStr & monthStr & dayStr
currentTime = hourStr & minuteStr & secondStr
on error goto 0
end function
We also need know how to prase a date or time string
'Description:
' Function to get prase date or time from string.
'Input:
' currentDate: the current date with string format eg. 20000101
' currentTime: the current time with string format eg. 010101
'Output:
' get_Year: Get current Year From currentDate
' get_Month: Get current Month From currentDate
' get_Day: Get current Day From currentDate
' get_Hour: Get current clock From currentTime
' get_Minute: Get current minutes From currentTime
' get_Second: Get current second From currentTime
'Throw Exception When:
' None
public function get_Year(currentDateStr)
on error resume next
get_Year = Left(currentDateStr, 4)
on error goto 0
end function
public function get_Month(currentDateStr)
on error resume next
get_Month = Left(Right(currentDateStr, 4),2)
on error goto 0
end function
public function get_Day(currentDateStr)
on error resume next
get_Day = Right(currentDateStr,2)
on error goto 0
end function
public function get_Hour(currentTimeStr)
on error resume next
get_Hour = Left(currentTimeStr,2)
on error goto 0
end function
public function get_Minute(currentTimeStr)
on error resume next
get_Minute = Right(Left(currentTimeStr,4),2)
on error goto 0
end function
public function get_Second(currentTimeStr)
on error resume next
get_Second = Right(currentTimeStr,2)
on error goto 0
end function
If you need convert string to a date object again, you can
'Description:
' Function to prase current date and time from string.
'Input:
' None.
'Output:
' prase_Date: the current date with system date format
' prase_Time: the current time with system time format
'Throw Exception When:
' None
public function prase_Date(currentDateStr)
on error resume next
prase_Date = CDate(get_Year(currentDateStr)&"/"&get_Month(currentDateStr)&"/"&get_Day(currentDateStr))
on error goto 0
end function
public function prase_Time(currentTimeStr)
on error resume next
prase_Time = CDate(get_Hour(currentTimeStr)&":"&get_Minute(currentTimeStr)&":"&get_Second(currentTimeStr))
on error goto 0
end function