erbsoftware
erbsoftware

Reputation: 365

JSON DateTime remove time in ASP.NET?

Let's say I have the following DateTime which has a value of: "2017-01-27T00:00:00".

How can I remove the above date to return only the date without the time and without changing the format? i.e return "2017-01-27"

Upvotes: 1

Views: 2445

Answers (2)

Dr. Roggia
Dr. Roggia

Reputation: 1125

If you need some customization for the date, you can use *name*.ToString('yyyy-MM-dd') to customize the result. See the documentation here

Upvotes: 0

Pedro Luz
Pedro Luz

Reputation: 973

Something like this maybe?

var dt = DateTime.Parse("2017-01-27T00:00:00");
return dt.ToString("yyyy-MM-dd");

Upvotes: 3

Related Questions