Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get start date and end date of selected month......Thanks in Advance
Posted
Comments
[no name] 3-Jun-14 9:22am    
Start date is easy, hint it's always the 1st. The end date is going to depend on the month selected. But a simple search should tell you how many days are in each month.

 
Share this answer
 
 
Share this answer
 
try this..: )

C#
DateTime startOfMonth = new DateTime(2014, 5, 1);   //new DateTime(year, month, 1);
DateTime endOfMonth = new DateTime(2014, 5, DateTime.DaysInMonth(2014, 5)); //new DateTime(year, month, DateTime.DaysInMonth(year, month));


and output is.. :)

5/1/2014 12:00:00 AM (StartDate)
AND
5/31/2014 12:00:00 AM(End Date)
 
Share this answer
 
Comments
HardikPatel.SE 3-Jun-14 9:35am    
my 5+
Nirav Prabtani 3-Jun-14 9:47am    
thank you .. :)
This example takes the current date from DateTime.Now and computes the first date of the month and the last date of the month.

C#
DateTime dt = DateTime.Now;
DateTime dtBegin = dt.AddDays(-(dt.Day - 1));
DateTime dtEnd = dtBegin.AddMonths(1).AddDays(-1);
Debug.WriteLine ("Begin Date: {0}",dtBegin);
Debug.WriteLine ("End Date: {0}",dtEnd);
 
Share this answer
 
... something like this:
C#
DateTime dtSelectedDate = DateTime.Now;
DateTime dtFirstDayOfMonth = new DateTime(1, dtSelectedDate.Month, dtSelectedDate.Year);
DateTime dtLastDayOfMonth = dtFirstDayOfMonth.AddMonths(1).AddDays(-1);

.. hope it helps.
 
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