[Solved] Convert string date to another format C#? [closed]


Use DateTime.ParseExact:

public string dateBirthday(string date)
{
   DateTime a = DateTime.ParseExact(date, "dd.MM.yyyy", CultureInfo.InvariantCulture);
   //return a.ToString("dd/MM/yyyy"); // original answer without culture
   return a.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
}

EDIT:
As Jon Skeet already said, the / is culture-dependent and we (you and me;)) did not specify a culture for the ToString() function, so the culture of the host environment will be used. To get your desired output specify/force a culture that uses / as date separator, like CultureInfo.InvaraintCulture.

3

solved Convert string date to another format C#? [closed]