get first and last day of current month c#

Brian
Brian
Participant
570 Points
75 Posts

Hi,
How to get first and last day of current month c#?

Views: 8304
Total Answered: 3
Total Marked As Answer: 0
Posted On: 05-May-2015 22:06

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Moderator
1172 Points
211 Posts
         

Hi Bob,

Use this:

DateTime FirstDay;
DateTime LastDay;
FirstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
LastDay = DateTime.Now.AddMonths(1).AddDays(-1);
Posted On: 05-May-2015 15:05
Heidi Fundinger
Heidi F...
2 Points
1 Posts
         

How would you change this to include leap years?  Thanks.

Posted On: 13-Dec-2016 07:35
Rahul Maurya
Rahul M...
Moderator
1172 Points
211 Posts
         

DateTime object includes leap year. I think it will care of it.

Posted On: 13-Dec-2016 09:02
 Log In to Chat