'******************************************************************************
' 函数名称: DateToStr
' 功能:将日期转换成字符串
' 参数:
' 用法: DateToStr(Now, "YYYY年MM月DD日HH时MI分SS秒") 返回 2001年01月01日12时00分00秒
'       DateToStr(Now, "YYYYMMDDHHMISS") 返回 20010101120000
'       更新数据库时如果只需要年月日则按如下处理:
'       DateToStr(Now, "YYYYMMDD0000") 返回 200101010000
' 返回值:
'******************************************************************************
Public Function DateToStr(curDate As Date, sFormat As String) As String
    DateToStr = ""    Dim sTemp As String
    Dim nPos1 As Integer, nPos2 As Integer
    If InStr(sFormat, "YYYY") > 0 Then
        sFormat = ReplaceStr(sFormat, "YYYY", Year(curDate))
    End If
    If InStr(sFormat, "MM") > 0 Then
        sTemp = Month(curDate)
        If Len(sTemp) = 1 Then sTemp = "0" & sTemp
        sFormat = ReplaceStr(sFormat, "MM", sTemp)
    End If
    If InStr(sFormat, "DD") > 0 Then
        sTemp = Day(curDate)
        If Len(sTemp) = 1 Then sTemp = "0" & sTemp
        sFormat = ReplaceStr(sFormat, "DD", sTemp)
    End If
    If InStr(sFormat, "HH") > 0 Then
        sTemp = Hour(curDate)
        If Len(sTemp) = 1 Then sTemp = "0" & sTemp
        sFormat = ReplaceStr(sFormat, "HH", sTemp)
    End If
    If InStr(sFormat, "MI") > 0 Then
        sTemp = Minute(curDate)
        If Len(sTemp) = 1 Then sTemp = "0" & sTemp
        sFormat = ReplaceStr(sFormat, "MI", sTemp)
    End If
    If InStr(sFormat, "SS") > 0 Then
        sTemp = Minute(curDate)
        If Len(sTemp) = 1 Then sTemp = "0" & sTemp
        sFormat = ReplaceStr(sFormat, "SS", sTemp)
    End If
    DateToStr = sFormat
End Function