I am using ASP RadControls for my project. I want to know how to set MinDate and MaxDate based on the Financial Year. I try following code but I am not getting how set min value and max value to datepicker. Kindly help me.
string finyear = ViewState["FIN_YR"].ToString();//viewstate["FIN_YR"]="1112"
string pr = finyear.Substring(0, 2);//pr="11"
string pr1 = "20";
string year1 =pr1+pr;//year1="2011"
int firstyear = Convert.ToInt32(year1);
string pa = finyear.Substring(2, 2);//pa="12"
string year2 = pr1 + pa;//year2="2012"
int Secondyear = Convert.ToInt32(year2);
dtpRemitDate.MinDate = System.DateTime.Parse("firstyear/4/1");
I tried like this but System.DateTime.Parse("int,int,int");
only acceptable. How can I set min Date to datepicker?
To start with, I would try to form far fewer string operations. It looks like you only need two:
Do the rest based on DateTime
and int
:
string financialYearText = ViewState["FIN_YR"].ToString();
int minYear2Digits = int.Parse(financialYearText.Substring(0, 2));
int maxYear2Digits = int.Parse(financialYearText.Substring(2, 2));
dtpRemitDate.MinDate = new DateTime(minYear2Digits + 2000, 4, 1);
dtpRemitDate.MaxDate = new DateTime(maxYear2Digits + 2000, 4, 1);
This assumes it will always be based on the year 2000 - if you have "old" records e.g. "8788" which should mean 1987 and 1988, you'd need to do a bit more work.