You need to sign in to do that
Don't have an account?
Michael Kolodner 13
Method that can accept a date as parameter?
I'm trying to write a method that will take a date and give the fiscal year it's in. Here's my code, which compiles:
But when I try to use this Execute Anonymous, I get an error " Line: 2, Column: 16 Unexpected token '('. "
public class dateTest { public static string giveFY(date givenDate) { system.debug('givendate is ' + givenDate); integer currentFiscalOrSchoolYear ; if (givenDate.Month() >= 7){ currentFiscalOrSchoolYear = givenDate.Year() + 1; } else { currentFiscalOrSchoolYear = givenDate.Year(); } system.debug('the month of givenDate is: ' + currentFiscalOrSchoolYear); //Get the last two digits string fy = (string.valueof(currentFiscalOrSchoolYear).right(2)); system.debug('fy to be returned: ' + fy); return fy; } }
But when I try to use this Execute Anonymous, I get an error " Line: 2, Column: 16 Unexpected token '('. "
system.debug('putting 2018-04-11 into dateTest'); dateTest.giveFY(2018-04-11); system.debug('FY is: ' + fy); system.debug('putting 2019-04-11 into dateTest'); dateTest.giveFY(2019-04-11); system.debug('FY is: ' + fy);
All Answers
Meanwhile, a question. I understand what you're doing with the Date.newinstance(). But is there any way to actually just type a data and hand it to a method?