Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign datetime value to today's date with specific time

Tags:

c#

datetime

I have a variable which is defined as a DateTime. I need to assign it today's date but have the time be 4 PM. How do I do this?

like image 413
Nate Pet Avatar asked Nov 01 '11 14:11

Nate Pet


People also ask

How do I get today's date in C#?

C# today's date Now; Console. WriteLine(now. ToString("F")); The example prints today's date.

What is DateTime MinValue in C#?

The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar. MinValue defines the date and time that is assigned to an uninitialized DateTime variable. The following example illustrates this. C# Copy.


1 Answers

You want DateTime.Today.AddHours(16)

DateTime.Today will return today's date at midnight.
You can also use the Date property to drop the time from an arbitrary DateTime value.

like image 129
SLaks Avatar answered Oct 08 '22 13:10

SLaks