get first and last day of current month c#

Brian
Brian
2376 Points
13 Posts

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

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

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
4916 Points
27 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...
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...
4916 Points
27 Posts
         

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

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