xXH4CK3RXx xXH4CK3RXx - 1 year ago 95
Vb.net Question

VB.net if Day(Now) = 1

I have started coding VB.net and am making a program.
I want this program to do something on a certain day (birthday)
I have Tried

If Date.Day(Now) = 1 And Month(Now) = 3 Then
MsgBox("Happy Birthday!")
End If

But Date.Day(Now) does not appear to be correct ( Month(Now) ) works fine)
The error it gives me is Operator '=' is not defined for types 'Date' and 'Integer'

Answer Source

Use the NET Framework DateTime structure and its properties instead

If DateTime.Now.Day = 13 And DateTime.Now.Month = 9 Then
    Console.WriteLine("Happy Birthday!")
End If

As hinted below in the comments, you are mixing calls to the VB6 compatibility library (Month(Now) from Microsoft.VisualBasic.dll) and calls to DateTime structure (Date alias), but the DateTime structure doesn't have a shared member called Day, instead it has a shared property named Now and from this property you can extract the Day value.

If you insist in using the Microsoft.VisualBasic compatibility library then your code should be

If Day(Now) = 13 And Month(Now) = 9 Then
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download