c pound

I reject your reality and substitute my own!
posts - 46, comments - 37, trackbacks - 40

My Links

News

Archives

Image Galleries

Blog Communities

Blog is a stupid word

Lunch Hour

Resources

Getting the first day of the month

I want to find out what day-of-week the first day of the month falls on. For example, the first of October falls on a Saturday.

DayOfWeek firstDayOfMonth = DateTime.Now.AddDays((DateTime.Now.Day - 1) * -1).DayOfWeek;

It seems to me like there should be a better (built-in) way to do this. Am I just missing something obvious?

Print | posted on Friday, October 21, 2005 12:05 PM |

Feedback

Gravatar

# re: Getting the first day of the month

Hi Dan,

I don't think there's anything built-in... I have another (slightly more readable) way of doing it, though:

DateTime now = DateTime.Now;
DateTime date = new DateTime(now.Year, now.Month, 1);
DayOfWeek dow = dt.DayOfWeek;

I realise that there may be a performance issue here, but it's been fine for me so far... Heh, I might be the one missing something!
10/24/2005 1:16 AM | Jannik Anker
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: