23

Possible Duplicate:
Format .NET DateTime “Day” with no leading zero

Is there a way to remove the leading zeros in the date format

For example, X.ToString("MM/dd/yy") returns 07/02/11 but I'd like it to instead return 7/2/11.

Is this possible?

Thanks

Community
  • 1
  • 1
Evan Layman
  • 3,691
  • 9
  • 31
  • 48
  • 3
    [Possible duplciate](http://stackoverflow.com/questions/988353/format-net-datetime-day-with-no-leading-zero) – Peter K. Jul 25 '11 at 18:30
  • 2
    http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx – Evan Mulawski Jul 25 '11 at 18:31
  • @Peter K. - Thanks I did not see that in my search. Is it proper to delete this since the answer is posted elsewhere? – Evan Layman Jul 25 '11 at 18:36
  • @Evan: No, because it has answers, you won't be able to delete it. The normal process seems to have taken its course, and the closure has been voted on. No worries! That's the way SO works. – Peter K. Jul 25 '11 at 18:49
  • @Peter - Okay thanks. Hopefully my question will be easier to find for others looking for the answer though :) – Evan Layman Jul 25 '11 at 20:05

5 Answers5

34

X.ToString("M/d/yy") is what you need

Neil Knight
  • 47,437
  • 25
  • 129
  • 188
reggie
  • 13,313
  • 13
  • 41
  • 57
6

Just remove the extra M and d.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
4

You can use "M/d/yy". See here for more details.

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
Szymon Rozga
  • 17,971
  • 7
  • 53
  • 66
1

You can write X.ToString("M/d/yy")

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
Vasea
  • 5,043
  • 2
  • 26
  • 30
1

It is X.ToString("M/d/y") if you want to remove ALL leading zeroes ;)

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
gangelo
  • 3,034
  • 4
  • 29
  • 43