5

I would like to format a standard .NET DateTime string as follows

2014-01-01 => Jan 2014

I can get the date form "January 2014" by using ToString("y") but how can I abbreviate the month?

Is this even possible?

C# Visual Studio 2012 .NET 4.5

Francesco B.
  • 2,729
  • 4
  • 25
  • 37
Steven Wood
  • 2,675
  • 3
  • 26
  • 51

2 Answers2

14

You can use the MMM format as in:

DateTime.Now.ToString("yyyy-MM-dd => MMM yyyy")

Which produces:

2014-08-06 => Aug 2014
Sina Iravanian
  • 16,011
  • 4
  • 34
  • 45
0

You can use "MMM", take a look at this example: http://msdn.microsoft.com/library/zdtaw1bw%28v=vs.110%29.aspx

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
  • I dont speak german but fortunately I know that page well in the english version. I am accepting @Sina Iravians answer as he gives actual code but thanks for the answer – Steven Wood Aug 06 '14 at 14:27