日付を比較する Date.Compare() - VB.NET
2018/1/9(火) 18:45 修正
日付の比較であれば、Date.Compareでよかったのかも
日付を比較するにはDate.Compareメソッドを使う。
Compare(t1, t2)となっている場合
- t1 < t2 の場合、負の数
- t1 = t2 の場合、0
- t1 > t2 の場合、正の数
例
今日の日付 と 8月31日 を比較する
' 現在の日付を取得 Dim today As Date = New Date() ' 現在の年の8月31日を生成 Dim compareDate As Date = New Date(today.Year, 8, 31) ' 現在が8月31日よりも前のため、「-1」が表示される MsgBox(Date.Compare(today, compareDate)