2017-09-27 5 views
0

분기에 기반한 답변을 찾았지만 다른 결제 기간으로 연장해야합니다. 나는 서클에 갔었 고 출구를 찾을 수 없습니다!현재 결제 기간 끝 찾기

Dynamics 365 (온라인)에서 작동하는 C# 콘솔 앱을 작성하고 있지만 더 많은 수학 문제가 있다고 생각합니다.

향후 갱신일이 설정된 회사가 있습니다 (예 : 2018 년 1 월 2 일 (1 월 2 일)

새 주문에 대한 청구 기간은 월별, 분기별로, 2 년마다 또는 연간 일 수 있습니다. 갱신 날짜로부터 거꾸로 작동하는 현재 청구 기간의 종료일을 계산해야합니다. 여기

내가

DateTime contractRenewal = new DateTime(2018, 02, 01); 
int MonthsInBillPeriod = getBillingPeriod() //returns 1 for monthly, 3 for quarterly etc. 
int currQuarter = (DateTime.Now.Month - contractRenewal.Month)/MonthsInBillPeriod + 1; 
int month = currQuarter * MonthsInBillPeriod + contractRenewal.Month; 
while (month > 12) 
    month = month - MonthsInBillPeriod; 
renewal = new DateTime(DateTime.Now.AddMonths(month).Year, month, 1).AddDays(-1); //should return 30/09/2017 for monthly. 31/10/2017 for quarterly. 31/01/2018 for biannual and annual given contractRenewal date 

답변

1

이 분기를 고려하지 않고, 충분히 같은 달을 처리하기위한 것이 아닙니다 지금까지이 무엇인가? 이와 같이 :

DateTime tmpRenewal = contractRenewal; 
while(tmpRenewal > DateTime.Now) 
{ 
    tmpRenewal = tmpRenewal.AddMonths(-MonthsInBillPeriod); 
} 

// need to go one period forward, to the future from Now (as we are in the past right now) 
DateTime renewal = tmpRenewal.AddMonths(MonthsInBillPeriod).AddDays(-1); 
+0

감사합니다. 간단하게 문제를 해결했습니다. –