Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare Created DateTime to DateTime.Today at 6pm, C#

Tags:

c#

.net

datetime

In C# I need to compare the value of DateTime.Today /6pm, to a field that stores the Created DateTime.

Basically there is certain functionality that is only accessible on the same day as the created day and then only till 6pm.

The part I am not fully understanding is how to accurately represent 6pm on Today to compare against. Is there a method that always returns, say, Midnight that I can then do a .AddHours(18); to?

Am I over-complicating this? Thanks.

like image 942
Refracted Paladin Avatar asked Nov 28 '22 23:11

Refracted Paladin


1 Answers

DateTime SixPmToday = DateTime.Now.Date.AddHours(18);

If you output this, say to console, you will have (in my regional settings):

5/24/2010 6:00:00 PM
like image 175
Kyle Rosendo Avatar answered Dec 09 '22 07:12

Kyle Rosendo