function date_get(Str1,this_type)
this_type=strtonum(this_type)
if not (isnull(str1)) and trim(str1)<>"" then
if len(year(str1))<=2 then
yearT="20" & year(str1)
else
yearT=year(str1)
end if
if len(month(str1))<=1 then
monthT="0" & month(str1)
else
monthT=month(str1)
end if
if len(day(str1))<=1 then
dayT="0" & day(str1)
else
dayT=day(str1)
end if
if len(hour(str1))<=1 then
hourT="0" & hour(str1)
else
hourT=hour(str1)
end if
if len(minute(str1))<=1 then
minuteT="0" & minute(str1)
else
minuteT=minute(str1)
end if
if this_type=1 then
if datediff("d",str1,now())=0 then
date_get="今日 " & hourT & ":" & minuteT
else
date_get=yearT & "-" & monthT & "-" & dayT
end if
elseif this_type=2 then
date_get=monthT & "-" & dayT
elseif this_type=3 then
date_get=yearT & "-" & monthT & "-" & dayT
elseif this_type=4 then
date_get=yearT & "年" & monthT & "月" & dayT & "日"
else
date_get=yearT & "-" & monthT & "-" & dayT & " " & hourT & ":" & minuteT
end if
end if
end function
说明
下面例子利用 FormatDateTime 函数把表达式格式化为长日期型并且把它赋给 MyDateTime:
Function GetCurrentDate
'FormatDateTime 把日期型格式化为长日期型。
GetCurrentDate = FormatDateTime(Date, 1)
End Function