我有一个开始日期,我有下一个财政年度的结束日期。那么,基于此数据如何获取完整的财政年度结束日期?
即。
start date = 23rd January,2019
financial year end date's day = 31
financial year end date's month = 3
And I want full date as below :
financial year end date = 31st March,2019
请帮助我获取日期。
答案 0 :(得分:3)
尝试为允许可变的开始日期:
DateTime startDate = new DateTime(2019,1,23);
DateTime financialYear = new DateTime(startDate.Year, 3,31);
if (startDate > financialYear)
{
financialYear = financialYear.AddYears(1);
}
然后将financialYear
格式化为所需格式
答案 1 :(得分:1)
var startDate = new DateTime(2019,1,23); //23rd January,2019
var financialYearEndDay = 31;
var financialYearEndMonth = 3;
DateTime financialYear = new
DateTime(date.Year,financialYearEndMonth,financialYearEndDay);
if (startDate > financialYear)
{
financialYear = financialYear.AddYears(1);
}
答案 2 :(得分:0)
如果我正确理解,您只需要一个新的DateTime
对象,该对象取startDate
的年份,但是日期和月份固定?然后假设您已经将startDate
作为DateTime
对象,则只需执行以下操作:
new DateTime(startDate.Year, financialYearEndMonth, financialYearEndDay)