Reputation: 2013
I've searched here for a solution, but I can't make it work for me.
My problem is:
I have a rotine where a email is sent each 2 minutes, but now I need to check the hour to send this email only once for day.
I need something like this
if(hourNow == '18')
send();
Can someone help me?
Upvotes: 2
Views: 7908
Reputation: 21
Try this:
var nowHour = DateTime.Now.Hour;
if(nowHour==18)
{
}
DateTime.Now gets current date and time, and .Hour get hour. You can do this with Day, Year, Month etc.
Upvotes: 1
Reputation: 149078
You can use DateTime.Now
to get the current date and time, and then the Hour
property to get the current hour of the day:
if (DateTime.Now.Hour == 18)
...
Upvotes: 2
Reputation: 23107
Try this:
var nowHour = DateTime.Now.Hour;
if(nowHour==18)
{
}
DateTime.Now
gets current date and time, and .Hour
get hour. You can do this with Day
, Year
, Month
etc.
Upvotes: 2
Reputation: 164341
The DateTime
type has an Hour
property that returns the hour of the day (0 - 23). You can use that:
if(DateTime.Now.Hour == 18)
send();
Upvotes: 10