Rocshy Rocshy - 1 month ago 13
C# Question

Current date without time

How can I get the current date but without the time? I am trying to convert the date from the "dd.mm.yyyy" format to "yyyy-MM-dd", because

DateTime.Now
returns the time too, I get an error (
String was not recognized as a valid DateTime
.) when I try to do the following.

string test = DateTime.ParseExact(DateTime.Now.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd");

Answer
String test = DateTime.Now.ToString("dd.MM.yyy");