get first and last day of current month c#

Brian
Brian
Moderator
2232 Points
14 Posts

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

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

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 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...
Member
10 Points
0 Posts
         

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

Posted On: 13-Dec-2016 07:35
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

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

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