Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Calendar c = Calendar.getInstance();
c.setTime(myDate);
int year = c.get(Calendar.YEAR);
package routines;
public class MyRoutineDemo {
public static int getFiscalYear(java.util.Date date) {
int year=date.getYear()+1900;
int fiscalYear=0;
java.util.Date standarDate=TalendDate.parseDate("MM/dd/yyyy","07/01/"+year);
if(TalendDate.compareDate(date, standarDate)>=0){
fiscalYear=year+1;
}else{
fiscalYear=year;
}
return fiscalYear;
}
}
Starting job forum21775 at 12:04 03/02/2012.
connecting to socket on port 3860
connected
.----------+----------+-----------.
| tLogRow_1 |
|=---------+----------+----------=|
|date |fiscalYear|fiscalMonth|
|=---------+----------+----------=|
|07/01/2009|2010 |1 |
|06/30/2010|2010 |12 |
|09/06/2011|2012 |3 |
'----------+----------+-----------'
disconnected
Job forum21775 ended at 12:04 03/02/2012.
Calendar c = Calendar.getInstance();
c.setTime(myDate);
int year = c.get(Calendar.YEAR);
To get any parts of a Date you have to use the class Calendar (it is an interface and there are a lot of implementations like GregorianCalendar).
To get the year do this:Calendar c = Calendar.getInstance();
c.setTime(myDate);
int year = c.get(Calendar.YEAR);