Leslie
Leslie

Reputation: 3644

check date for variable value

I have a variable in my Java class that needs to be set based on whether today is before or after 7/1. If today is before 7/1 then we are in fiscal year that is the current year (so today we are in FY10). If today is after 7/1 our new fiscal year has started and the variable needs to be the next year (so FY11).

psuedo code:

if today < 7/1/anyyear then
  BudgetCode = "1" + thisYear(YY)  //variable will be 110
else
  BudgetCode = "1" + nextYear(YY)  //variable will be 111

thanks!

Upvotes: 1

Views: 442

Answers (2)

ProfessionalAmateur
ProfessionalAmateur

Reputation: 4563

I think the if statement would be like this to get the 2 digit year with the "1" digit on the front end of it.

if (cal.after(someDate)) {
  BudgetCode = "1".concat(new Integer(cal.get(Calendar.YEAR)%100).toString());
}
else {
  BudgetCode = "1".concat(new Integer(cal.get(Calendar.YEAR)%100).toString());
}

Upvotes: 0

mamboking
mamboking

Reputation: 4637

Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.JULY);
cal.set(Calendar.DATE, 1);

if (cal.after(someDate)) {
  fy = cal.get(Calendar.YEAR) + 1;
}
else {
  fy = cal.get(Calendar.YEAR);
}

Upvotes: 3

Related Questions