Calculating sum of field by current year and previous year

I am trying to sum CustInvoiceJour.invoiceamount for dates included in this calendar year, by dates in the previous year, e.t.c. Here is the code I have so far. Hopefully it gives you an idea of what I’m trying to do, although it doesn’t work. I believe my select statement is getting the correct sum for this year but I have no idea how to return that value (or if I should even use a select statement). Any help would really be appreciated.

public static void YTD()

{

CustInvoiceJour custInvoiceJour;

str cDateStr = date2str( today(),321,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4);

str cYear=substr(cDateStr,1,4);

str cYearStart = strFmt("%1/01/01",cYear);

str cYearEnd = strFmt("%1/12/31",cYear);

date CYSD = str2Date(cYearStart, 321);

date CYED = str2Date(cYearEnd, 321);

select sum(invoiceamount) from custInvoiceJour where custInvoiceJour.InvoiceDate >= CYSD;

}

Thanks again for the help. If I can get this I’m sure my boss will be impressed :wink: