Wednesday, May 9, 2007

Converting C# month from int to Name

If you want to know what month no. 1 is in text, this piece of code comes in handy

DateTime.Parse("01-JAN-1970").AddMonths(intMonth ).ToString("MMMM")

Handy tip

This assumes that intMonth is zero-based. Otherwise, use intMonth - 1. If you're doing it repeatedly, you want to store the results of DateTime.Parse(), natch.

No comments: