如果日期是(特定日期)那么

时间:2014-04-13 21:33:32

标签: vb.net

如果有特定日期,我如何让我的应用程序执行活动?我似乎找不到有用的东西。年份并不重要,只需要一天一个月就可以了。

3 个答案:

答案 0 :(得分:1)

因为您想要匹配日期和月份:

Dim myDate As Date = Date.Now
Dim someMonth As Integer = 4
Dim someDay As Integer = 13

If myDate.Month = someMonth AndAlso myDate.Day = someDay Then
    ... month and day are matched
End If

答案 1 :(得分:0)

使用IsDate ....

If IsDate(MyDate) Then.....

更新定义日期的各种方式

'DateTime constructor: parameters year, month, day, hour, min, sec
 Dim MyDate1 As New Date(2012, 12, 10, 12, 0, 0)

 'initializes a new DateTime value
  Dim MyDate2 As Date = #12/10/2012 12:00:52 AM#

 'using properties
  Dim MyDate3 As Date = Date.Now
  Dim MyDate4 As Date = Date.UtcNow
  Dim MyDate5 As Date = Date.Today

答案 2 :(得分:0)

尝试这样的事情:

Dim thisDate As Date = New Date(2014, 4, 13)  ' Assuming this is provided
Dim certainDate As Date = New Date(2013, 4, 13)   ' Assuming this is provided

If thisDate = New Date(thisDate.Date.Year, certainDate.Month, certainDate.Day) Then
    Debug.Print("dates equal excluding year")
Else
    Debug.Print("dates UNequal excluding year")
End If

请记住,这将始终创建一个新的日期对象进行比较,但它可以正常工作。

希望它有所帮助!