Solved

Function to calculate fiscal year from date passed in java

Posted on 2013-01-09
3
3,474 Views
Last Modified: 2013-11-13
Hi,

I need a function which calculates the fiscal year and returns true or false based on the date passed. Our system financial fiscal year is Apr 01 - Mar 31.

For ex. Current year is 2013. If the passed date is 2012-12-12 (YYYY-MM-DD) then the function should return true. If the passed date is 2012-01-12 (YYYY-MM-DD) then the function should return false.

Thanks in advance.
0
Comment
Question by:manohar27
  • 2
3 Comments
 

Author Comment

by:manohar27
ID: 38759975
test
0
 

Author Comment

by:manohar27
ID: 38760476
Bit Correction here:

For ex. Current year is 2013. If the passed date is 2012-12-12 (YYYY-MM-DD) then the function should return false. If the passed date is 2011-12-12 (YYYY-MM-DD) then the function should return true.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 38762757
public static Boolean fiscal(String date){
     Calendar now = Calendar.getInstance();
     int year=now.get(Calendar.YEAR) - (now.get(Calendar.MONTH) < 4?1:0);
     String start=year + "-04-01";
     String end=(year+1) + "-03-31";
     return !(date.compareTo(start)>=0  && date.compareTo(end) <= 0);
    }
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question