Click here to Skip to main content
15,881,875 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
Hi All,

I am using a drop down list for selecting the month in .aspx page.
I have to get last date of the selected month in .aspx.cs page.
(some months have 30 days and some have 31 days)

How can I do this?


Regards,

N.SRIRAM
Posted
Updated 15-Aug-18 23:44pm
v2
Comments
Dalek Dave 20-Jan-11 3:42am    
Edited for Readability.

Hi,

User
DateTime.DaysInMonth(int year,int month)  


Pass year and month you select. function return total days in month.

umesh
 
Share this answer
 
Comments
Rajesh Anuhya 20-Jan-11 3:00am    
Good answer
soni uma 20-Jan-11 3:00am    
thnx
JF2015 20-Jan-11 3:00am    
Good answer
Pravin Patil, Mumbai 20-Jan-11 3:33am    
100% Correct
Dalek Dave 20-Jan-11 3:42am    
Couldn't put it better myself.
Hi,
C#
DateTime origDT = Convert.ToDateTime("02/10/2011");
DateTime lastDate = new DateTime(origDT.Year, origDT.Month, 1).AddMonths(1).AddDays(-1);

Hope this may help you.
 
Share this answer
 
v3
Comments
JF2015 20-Jan-11 3:59am    
Very good alternative to the previous post. 5+
Blesson Mathew 20-Jan-11 4:05am    
Thank you JF2015
Member 8233601 18-Jun-13 3:23am    
5+
DateTime last_Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1);
 
Share this answer
 
Comments
CHill60 16-Aug-18 7:03am    
This really isn't any different to Solution 3 from 2011, just using Now instead of a specific date, meaning your version is less suited as a solution to the question actually asked. Make sure you are not repeating what someone else has already suggested and remember to read the question carefully
See Here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900