两个由日期挑选器返回日期字符串的函数,大家多提意见.
两个函数的功能都是通过一个日期挑选器dtpicker,得到形如"2007/05/12"这种格式的日期。 我写了两个,大家看看哪个更好些。呵呵
'--------------------------------------
'返回日期挑选器控件的日期
'参数:日期挑选器
'返回格式:yyyy/mm/dd[分隔符可设定]
'创建日期:2007-8-21
'修改日期:2007-8-21
'--------------------------------------
Public Function getDtDate(ByRef dt As DTPicker, Optional ByVal vstrSplit As String = "/") As String
On Error GoTo errhandler
Dim strdate As String * 10
strdate = Format(dt.Value, "yyyy-mm-dd")
getDtDate = Replace(strdate, "-", vstrSplit)
Exit Function
errhandler:
getDtDate = ""
End Function
'--------------------------------------
'返回日期挑选器控件的日期
'参数:日期挑选器
'返回格式:yyyy/mm/dd[分隔符可设定]
'创建日期:2007-8-21
'修改日期:2007-8-21
'--------------------------------------
Public Function getDtDate2(ByRef dt As DTPicker, Optional ByVal vstrSplit As String = "/") As String
On Error GoTo errhandler
Dim strYear As String * 4, strMonth As String * 2, strDay As String * 2
strYear = Trim(dt.Year)
If dt.Month <= 9 Then
strMonth = "0" & Trim(dt.Month)
Else
strMonth = Trim(dt.Month)
End If
If dt.Day <= 9 Then
strDay = "0" & Trim(dt.Day)
Else
strDay = Trim(dt.Day)
End If
getDtDate2 = strYear & vstrSplit & strMonth & vstrSplit & strDay
Exit Function
errhandler:
getDtDate2 = ""
End Function