简体   繁体   English

如何在C#编码中根据财务年度设置RaddatePicker最小日期和最大日期?

[英]How to set RaddatePicker Min Date and Max Date Based on Financial Year in C# Coding?

I am using ASP RadControls for my project. 我正在为我的项目使用ASP RadControls。 I want to know how to set MinDate and MaxDate based on the Financial Year. 我想知道如何根据财政年度设置MinDate和MaxDate。 I try following code but I am not getting how set min value and max value to datepicker. 我尝试下面的代码,但我没有得到如何设置最小值和最大值为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"); 我试过这样但是System.DateTime.Parse("int,int,int"); only acceptable. 只接受。 How can I set min Date to datepicker? 如何将min Date设置为datepicker?

To start with, I would try to form far fewer string operations. 首先,我会尝试,形成少得多的字符串操作。 It looks like you only need two: 看起来你只需要两个:

  • Parsing the min year with an implicit "2000" base 用明确的“2000”基础解析最小年份
  • Parsing the max year with an implicit "2000" base 用隐含的“2000”基础解析最大年份

Do the rest based on DateTime and int : 其余的基于DateTimeint

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 eg "8788" which should mean 1987 and 1988, you'd need to do a bit more work. 这假设它总是基于2000年 - 如果你有“旧”记录,例如“8788”,这应该意味着1987年和1988年,你需要做更多的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C#设置raddatepicker日期输入框 - how to set raddatepicker date input box with c# "<i>How i can set date picker range with in a financial year based on the document date?<\/i>如何根据文档日期在财政年度中设置日期选择器范围?<\/b> <i>Im using JQUERY to do this<\/i>我使用 JQUERY 来执行此操作<\/b>" - How i can set date picker range with in a financial year based on the document date? Im using JQUERY to do this 如何使用数据库检索日期设置raddatepicker日期 - How to set raddatepicker date with database retrieved date 如何在 C# 中将连续日期范围列表切割成财政年度列表? - How to chop a continuous date range list into a list of financial year in C#? 根据下拉值设置2个日期选择器的最小日期和最大日期 - Set the min date and max date of 2 datepickers based on dropdown value 使用Java脚本将日期设置为raddatepicker - Set the date to raddatepicker by using Javascript 在RadDatePicker中将当前PC日期和时间设置为默认值 - Set current PC date and Time as Default in RadDatePicker 最小日期和最大日期 - Min Date and Max date 在WebBrowser组件中设置日期值RadDatePicker - set date value RadDatePicker in WebBrowser component 如何设置最大和最小日期/时间选择器的范围 - How to set a range for the Max and Min Date/Time Picker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM