I am using Calender Extender Control in the AjaxControlToolkit. There are basically 2 controls of date : Start Date
and End date
(both associated with calender extender). Based on start Date selected, I populate date in the end date field like adding no of months or days. But like I have been able to add months, but also wants to set a particular day of that month which I am unable to do.
Example:
Today date is 18 Dec 2012
. Something like 1st of every three months, So I add 3 months the month comes out to be Feb 2013
. But I want to set Day 1st Feb 2013
. I am unable to do it. Kindly help.
You can set whatever day of month by add month.
DateTime todayDate = DateTime.Now;
DateTime after3MonthDate = todayDate.AddMonths(3);
//Set First Day of Month
after3MonthDate = new DateTime(after3MonthDate.Year, after3MonthDate.Month, 1);
This code can be used for existing date time variable to set the day part to the first day of the month:
if(myDate.Day > 1)
{
myDate = myDate.AddDays(-(myDate.Day - 1));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With