[Solved] How to convert day and compare this with first day of month?


To get the first day of the month, you could make use of DateTime class methods and properties alone.

DateTime dt = DateTime.Now; //change this to any date you want
DateTime firstDayOfMonth = dt.AddDays(1-dt.Day); //the trick is here, minus the DatetTime by the current day (of month) + 1, you necessarily get the first day of the month
DayOfWeek dow = firstDayOfMonth.DayOfWeek; //this is the first day of the month (this month's first day is Tuesday)

If you need first day of month, use firstDayOfMonth. If you need the day of week on the day, use dow. If you want to compare the firstDayOfMonth with some other DateTime but only interested in comparing the date, simply do:

firstDayOfMonth.Date == someOtherDays.Date

And if you need to use the time too, you could check TimeOfDay.

Basically, try to find out more about the DateTime class methods and properties. The class is really handy to use for such task as yours!

Edit: to compare both day and month (but not year), use DateTime.Day and DateTime.Month properties

5

solved How to convert day and compare this with first day of month?