求VB检查时间函数???
如题!
分别检查,小时,分钟,秒,是否符合规范.
请问如何解决啊!
或者说统一检查也行的,不一定要分小时,分钟,秒的.
[解决办法]
你的时间格式是怎样的?
貌似这种可以用正则表达式检查.
下面是一个检查日期格式为:YYYY-MM-DD HH:MI:SS 的程序,供参考.
Private Sub Command1_Click()
Dim str1 As String
str1 = "^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$ "
MsgBox (TestRegExp(str1, "2007-01-07 12:11:2 "))
End Sub
Function TestRegExp(myPattern As String, myString As String) As Boolean
Dim objRegExp As RegExp
Dim objMatch As Match
Dim RetStr As String
Set objRegExp = New RegExp
objRegExp.Pattern = myPattern
objRegExp.IgnoreCase = True
objRegExp.Global = True
If (objRegExp.Test(myString) = True) Then
RetStr = "True "
TestRegExp = True
Else
RetStr = "false "
TestRegExp = False
End If
TestRegExp = RetStr
End Function
工程引用Microsoft VBScript Regular Expressions 5.5
[解决办法]
函数:isdate
[解决办法]
DayToDay = Abs(DateDiff( "d ", Now, BackUpdate))
[解决办法]
isdate