# Re: 请问VB 存取资料库时,有关日期格式的问题(急)

Posted by 小飞虾 on April 01, 1999 at 16:59:52:

In Reply to: 请问VB 存取资料库时,有关日期格式的问题(急) posted by 小黄 on March 30, 1999 at 09:46:47:

你的问题，前阵子我碰过，答案和他差不多。不过我想到一种解决方式:

textbox 仍然当做textbox，input text string,在save to database 时执行转换。注意在转入前要check 一下IsDate(txtstring )，有何好意见，请见告。

CDateFormat = "ee/mm/dd"

Public Function toEDate(txtDate As Variant) As Variant
' 民国转换西元
Dim i, ee As Long
If IsNull(txtDate) Then
toEDate = Null
ElseIf txtDate = "" Then
toEDate = Null
Else
i = InStr(1, txtDate, "/", vbTextCompare)
ee = Val(Left(txtDate, i - 1)) + 1911
toEDate = CDate((Str(ee) + Mid(txtDate, i)))
End If
End Function

Public Function toCDate(dtmDate) As String
' 西元转民国
If IsNull(dtmDate) Then
toCDate = ""
Else
toCDate = Format(dtmDate, CDateFormat)
End If
End Function

Follow Ups: