Format DateTime.Now to yyyy-mm-dd

According to msdn MM format specifier stands for month and mm – for minutes.

“mm” | The minute, from 00 through 59.

“MM” | The month, from 01 through 12.

So your code should look like the following:

    var dateString1 = DateTime.Now.ToString("yyyyMMdd");
    var dateString2 = DateTime.Now.ToString("yyyy-MM-dd");

    Console.WriteLine("yyyyMMdd " + dateString1);
    Console.WriteLine("yyyy-MM-dd "+ dateString2);

And you will get the desired result

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)