以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何判断快速目标数据是否为日期  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=74287)

--  作者:goodnight
--  发布时间:2015/9/7 20:38:00
--  如何判断快速目标数据是否为日期

如 rq1 ="20150902"

   rq2 ="20150833"

   rq3="201509"

   rq4:="201515"

 

如何快速判断 rq1可以是日期型数据  rq2 不是日期型数据

                  rq3可以是日期型数据  rq4 不是日期型数据


--  作者:大红袍
--  发布时间:2015/9/7 20:47:00
--  
Dim str As String = "20150932"
Dim d As Date
Select Case str.Length
    Case 4
        Date.TryParse(str & "-1-1", d)
    Case 6
        Date.TryParse(str.SubString(0,4) & "-" & str.SubString(5,2) & "-1", d)
    Case 8
        Date.TryParse(str.SubString(0,4) & "-" & str.SubString(4,2) & "-" & str.SubString(6,2), d)
End Select
If d = Nothing Then
    msgbox("不是日期")
Else
    msgbox(d)
End If