0

I need to format a date into this specific format "1/23/2021" but for some reason it always returns as 1-23-2021 instead.

new DateTime().ToString("M/dd/yyyy")

What am I doing wrong?

Dmitry Bychenko
  • 165,109
  • 17
  • 150
  • 199
Kristofer
  • 649
  • 8
  • 22

1 Answers1

2

Separators are culture dependent. Try providing custom separator. For current date it can be

 DateTime.Now.ToString("M'/'dd'/'yyyy")

For arbitrary myDate date

 myDate.ToString("M'/'dd'/'yyyy")
Dmitry Bychenko
  • 165,109
  • 17
  • 150
  • 199