LOLZguy712
LOLZguy712

Reputation: 57

If date is (certain date) then

How would I make my application do an event when there is a certain date? I can't seem to find something that works. Year doesn't matter, just day and month is all I need.

Upvotes: 0

Views: 454

Answers (3)

Dave Doknjas
Dave Doknjas

Reputation: 6542

Since day and month is all you want to match on:

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

Upvotes: 1

NeverHopeless
NeverHopeless

Reputation: 11233

Try something like this:

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

Rememebr, this will always create a new date object for comparison but it works.

Hope it helps!

Upvotes: 0

Mych
Mych

Reputation: 2563

Use IsDate....

If IsDate(MyDate) Then.....

Update various ways of defining date

'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

Upvotes: 0

Related Questions