Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# : How to get number of days from an object of DateTime

Tags:

c#

datetime

In C# ,How can i find the number of days in a month which resides in a DateTime object.

Ex :

DateTime objDate=new DateTime();

using the objDate, now i want to get the number of days of the current month. IS there any built-in function present in C# ?

Leap years also has to be taken care of

like image 345
user198880 Avatar asked Nov 04 '09 10:11

user198880


2 Answers

int noOfDays = DateTime.DaysInMonth(objDate.Year, objDate.Month);
like image 155
Fermin Avatar answered Sep 28 '22 16:09

Fermin


int days = DateTime.DaysInMonth(objDate.Year, objDate.Month);
like image 35
djdd87 Avatar answered Sep 28 '22 16:09

djdd87