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?
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With