-2

My date changes values when I format it to "yyyy-mm-dd". It becomes "2019-54-10" instead of keeping the correct DateTime.Now. Bellow is my code:

public static DateTime CurrentDate = DateTime.Now;
ConvertedCurrentDate = CurrentDate.ToString("yyyy-mm-dd");
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
William
  • 201
  • 3
  • 7

3 Answers3

5

mm stands for Minute
you have to use MM

CurrentDate.ToString("yyyy-MM-dd");
PandaPlayer
  • 162
  • 9
1
ConvertedCurrentDate = CurrentDate.ToString("yyyy-MM-dd");

You need MM for the month :)

sephiroth
  • 896
  • 12
  • 22
0
/* Date strings */
public static string TodayNum = DateTime.Now.ToString("dd");        // e.g 07
public static string ThisMonthNum = DateTime.Now.ToString("MM");    // e.g 03
public static string ThisMonthShort = DateTime.Now.ToString("MMM");  // e.g Mar
public static string ThisMonthLong = DateTime.Now.ToString("MMMM");  // e.g March
public static string ThisYearNum = DateTime.Now.ToString("yyyy");   // e.g 2014
terrencep
  • 675
  • 5
  • 16