Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime.Today , beginning or end of the day?

Tags:

c#

datetime

I am using DateTime.Today.

Now I'm not sure if the date is from the beginning of the day or the end of the day.

This is what DateTime.Today returns : {11-3-2014 0:00:00}

like image 393
MCollard Avatar asked Mar 11 '14 10:03

MCollard


People also ask

What is today's DateTime?

The DateTime. Now property returns the current date and time, for example 2011-07-01 10:09.45310 . The DateTime. Today property returns the current date with the time compnents set to zero, for example 2011-07-01 00:00.00000 .

What does DateTime now return?

The Now property returns a DateTime value that represents the current date and time on the local computer.

What is a DateTime?

The DateTime value type represents dates and times with values ranging from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar. Time values are measured in 100-nanosecond units called ticks.

How do you start day and end day of month?

We can use the EOMONTH formula to find the first day of the month as well. EOMONTH returns the last day of a month from a date. Here, we use the EOMONTH function to go to the last day of the previous month. Then, we add 1 to get the first day of the current month.


2 Answers

MSDN states the following: "An object that is set to today's date, with the time component set to 00:00:00."

This means that a DateTime object is created with today's date at the absolute start of the day hence 00:00:00.

You can check if it is the start of the day by using the AddHour() method of the DateTime class.

DateTime d = DateTime.Today;
//AddHours, AddMinutes or AddSeconds
d = d.AddHours(1);
if (d.Date != DateTime.Today.Date) 
{ 
   //Not the same day
}

If d.date should be different the date was initialised at a different time (eg. 23:00:01).

http://msdn.microsoft.com/en-us/library/system.datetime.today(v=vs.110).aspx

like image 57
Speedy Codezales Avatar answered Oct 20 '22 18:10

Speedy Codezales


Thats the beginning of the day, the end of the day would be:

{11-3-2014 23:59:59}

And remember, the only stupid question is the one you don't ask :)

like image 21
javierfdezg Avatar answered Oct 20 '22 16:10

javierfdezg