RnR
RnR

Reputation: 209

C# datetime midnight time Format

I want to run a report where i want to pass parameters as starttime which is yesterday 12 am(midnight) and enddate as today 12 am (mid night), how to get midnight time in datetime format in c#

Upvotes: 3

Views: 11639

Answers (5)

Kishore Kumar
Kishore Kumar

Reputation: 12874

From Date: DateTime.Today.AddDays(-1)
To Date:   DateTime.Today

Upvotes: 1

John Woo
John Woo

Reputation: 263723

how about you pass the following format? yyyy-MM-dd HH:mm:ss so if applied in you code:

it should be 2012-05-12 00:00:00 to 2012-05-13 00:00:00

don't forget to include the time.

Upvotes: 1

Habib
Habib

Reputation: 223267

DateTime.Today

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

Console.Write(DateTime.Today);

Output:

5/11/2012 12:00:00 AM

Upvotes: 3

Vipin Nair
Vipin Nair

Reputation: 515

The answer is here.Just you have to search properly.Anyways here is the answer ,just use

DateTime.Today for today's date

Upvotes: 2

Michael Christensen
Michael Christensen

Reputation: 1786

Current date without any time (at midnight)

DateTime.Today

Yesterday at midnight

DateTime.Today.AddDays(-1)

Upvotes: 10

Related Questions