John White
John White

Reputation: 93

Check Day & Month of Current Date

I need to check the day and the month. I'm using Date.Now.

for example:

if day =9 and month=10 then do action

How can i do that?

Upvotes: 5

Views: 50843

Answers (6)

Sasiru Welgama
Sasiru Welgama

Reputation: 1

Dim today = Date.Today
    Dim day = today.day
    Dim month = today.Month
    Dim year = today.Year



    If day = 10 And Also month = 10 Then
        Label1.Text = today . Day
        Label2.Text = today . Month
        Label3.Text = Date . Today
        Label4.Text = Time Of Day
        Label5.Text = year

Upvotes: 0

Peter Mankge
Peter Mankge

Reputation: 79

Date.today.day      
Date.today.month

Upvotes: 0

slolife
slolife

Reputation: 19870

Use the Day and Month properties of a DateTime variable:

Dim currentDate As DateTime = DateTime.Now
If currentDate.Month = 10 AndAlso currentDate.Day = 9 Then
   'Do something
End If

Upvotes: 10

Tim Schmelter
Tim Schmelter

Reputation: 460108

The Date object has a Day and a Month property:

Dim today = Date.Today
Dim day = today.Day
Dim month = today.Month

If day = 9 AndAlso month = 10 Then
    ' do something ...
End If

Note that i've used Date.Today instead of Date.Now since you're interested in the date part anyway.

Upvotes: 4

Mark Hurd
Mark Hurd

Reputation: 10931

Dim today = Date.Now.Date
If today.Day = 9 AndAlso today.Month = 10 Then ...

Upvotes: 1

Jason Tyler
Jason Tyler

Reputation: 1389

Date.Now.Month and Date.Now.Day. Those are properties on the Date type.

Upvotes: 2

Related Questions