[英]Compare two dates in vb.net whether they are equal or not
我有一個Date變量startdt
和一個String變量hdnsdate
。
假設startdt
的值格式為3/1/ 2012 , hdnsdate
的值格式為03/01/2012 。 然后我如何比較vb.net中這兩個日期相等。
if
我的程序狀況良好,我想進行此檢查。 如果兩個日期匹配, if
移出if
循環,否則進入if
循環。
例如,C#中的示例正是我想要的。
if(startdt !=hdnsdate)
{
//Do
}
else
{
//Do this
}
使用Parse,ParseExact方法將hdnsdate
(字符串)解析為Date類型,並使用DateTime.Compare , Equals
和CompareTo
方法。
至今字符串
Dim enddate as Date
Date.TryParse(hdnsdate, enddate)
If startdt = enddate Then
'Do this
Else
'Do this
End If
比較日期的替代方法:
Dim result = DateTime.Compare(date1, date2)
If result=0 Then
'Do this
End If
Dim result = DateTime.Compare(hdnsdate, date2)
If result=0 Then
'Do this
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.