I want to convert DateTime.Now to yyyy-mm-dd format, as this is the only format I can use in my query that I want to include.
The default format for DateTime.Now looks like 5/1/2008 6:32:06 PM .
If I want to change its format to yyyyMMdd , I could use this line of code:
var dateString1 = DateTime.Now.ToString("yyyyMMdd");
But, when I try to do the same for this yyyy-mm-dd format, as shown below:
var dateString2 = DateTime.Now.ToString("yyyy-mm-dd");
The result that I got is incorrect. For the following lines of code:
var dateString1 = DateTime.Now.ToString("yyyyMMdd"); var dateString2 = DateTime.Now.ToString("yyyy-mm-dd"); Console.WriteLine("yyyyMMdd " + dateString1); Console.WriteLine("yyyy-mm-dd "+ dateString2);
I get the following result:

which is not true for the second case.
What am I missing?
source share