I have a dataset that I need to remove all records that are outside of the current financial year. I have a function that returns a boolean that suggests if the record will be deleted or not, for some reason it is telling me to delete records that are inside the current financial year... Maybe a logic issue?
The Function:
public static Boolean GetCurrentFinancialYear(DateTime CompareDate)
{
TimeSpan diff = DateTime.Now - CompareDate;
double Years = diff.TotalDays / 365.25;
double Months = diff.TotalDays / 12;
Boolean DeleteRecord = false;
var CurrentYear = DateTime.Today.Year;
var CurrentMonth = DateTime.Today.Month;
if(CompareDate.Month == 10 && CompareDate.Year == 2017)
{
var something = "nothing";
}
if (Months >= 13)
{
/// This is over a year old, safe bet its last finacial year or earlier
///
DeleteRecord = true;
}
else
{
var CurrentEndDate = new DateTime(DateTime.Now.Year, 7, 1);
var CurrentStartDate = new DateTime(DateTime.Now.Year - 1, 6, 30);
TimeSpan Enddiff = CurrentEndDate - CompareDate;
TimeSpan Startdiff = CurrentStartDate - CompareDate;
double EndMonths = Enddiff.TotalDays / 12;
double StartMonths = Startdiff.TotalDays / 12;
if (EndMonths < 12 && StartMonths > 0)
{
DeleteRecord = false;
}
else
{
DeleteRecord = true;
}
}
return DeleteRecord;
}