以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  文本转日期  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=107762)

--  作者:home8225
--  发布时间:2017/10/9 15:24:00
--  文本转日期
通过sql 加载的查询表的日期是字符格式的,格式为:2017-01-01,现在想把这个字符格式的日期转换为日期格式与当天的日期进行比较,求助代码怎么写?
--  作者:有点甜
--  发布时间:2017/10/9 15:39:00
--  

参考代码

 

dim str as string = “2017-01-01”
Dim d As Date
If Date.TryParse(str, d) Then
    If d < Date.today Then
        msgbox("日期小于今天")
    End If
    Dim sp As TimeSpan = Date.Today - d
    msgbox("相差" & sp.TotalDays)
Else
    msgbox("日期无效")
End If