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
  • 180,369
  • 20
  • 160
  • 215
Kristofer
  • 809
  • 9
  • 24

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
  • 180,369
  • 20
  • 160
  • 215