Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
satyavar
Contributor III
Contributor III

[resolved] How to display week number

Hi
I have a need to show CalendarYearweek and FiscalYearweek based on a configurable start date extending till 5000 days. Here Calendar Year means 1st Jan to 31st Dec and Fiscal Year means 1st July to 30th June.
For CalendarYearweek: I did it this way: Integer.parseInt(TalendDate.formatDate("w", row1.date)) when i do this, i get all week numbers accurately except for the last week of 2011. My custom start date is from 01st July 2010, Last week of 2010 i.e., Dates in YYYYMMDD - (20101226 to 20101231) is showing as 1 instead of 53.
For Fiscal Year: How do I calculate the Fiscal Year week assuming the financial year starts at July 1st of ever year?
Best Regards,
Kalyan
Labels (2)
1 Solution

Accepted Solutions
rbaldwin
Creator
Creator

Hello,
You can do a little bit of math to calculate what you seem to want.  I've broken this up into multiple lines to make it more readable, but you could cram them into a single line:
//get the date as a date.
Date date = TalendDate.parseDate("yyyyMMdd","20101231");
//get month as a number NOTE: this starts at 0 for January and goes to 11 for December.
int month = TalendDate.getPartOfDate("MONTH",date);
//get week of year*
int weekOfYear = TalendDate.getPartOfDate("WEEK_OF_YEAR",date);
//get our desired calendar year, 26 is chosen arbitrarily since it's simply the halfway point of a year.
int calendarWeek = month==11 && weekOfYear < 26 ? weekOfYear+52 : weekOfYear;
//get fiscal week.
int fiscalWeek = calendarWeek > 26 && month>=6 ? calendarWeek-26 : calendarWeek+26;

Will output the following for the dates included in the print statements:
 connecting to socket on port 4063
connected
month = 5
various week stuff for date: 20100630
Week of Year
Calendar: 27
Fiscal: 53
month = 6
various week stuff for date: 20100701
Week of Year
Calendar: 27
Fiscal: 1
month = 11
various week stuff for date: 20101226
Week of Year
Calendar: 53
Fiscal: 27
month = 11
various week stuff for date: 20101231
Week of Year
Calendar: 53
Fiscal: 27
month = 0
various week stuff for date: 20100101
Week of Year
Calendar: 1
Fiscal: 27
disconnected


Hope that helps!

View solution in original post

1 Reply
rbaldwin
Creator
Creator

Hello,
You can do a little bit of math to calculate what you seem to want.  I've broken this up into multiple lines to make it more readable, but you could cram them into a single line:
//get the date as a date.
Date date = TalendDate.parseDate("yyyyMMdd","20101231");
//get month as a number NOTE: this starts at 0 for January and goes to 11 for December.
int month = TalendDate.getPartOfDate("MONTH",date);
//get week of year*
int weekOfYear = TalendDate.getPartOfDate("WEEK_OF_YEAR",date);
//get our desired calendar year, 26 is chosen arbitrarily since it's simply the halfway point of a year.
int calendarWeek = month==11 && weekOfYear < 26 ? weekOfYear+52 : weekOfYear;
//get fiscal week.
int fiscalWeek = calendarWeek > 26 && month>=6 ? calendarWeek-26 : calendarWeek+26;

Will output the following for the dates included in the print statements:
 connecting to socket on port 4063
connected
month = 5
various week stuff for date: 20100630
Week of Year
Calendar: 27
Fiscal: 53
month = 6
various week stuff for date: 20100701
Week of Year
Calendar: 27
Fiscal: 1
month = 11
various week stuff for date: 20101226
Week of Year
Calendar: 53
Fiscal: 27
month = 11
various week stuff for date: 20101231
Week of Year
Calendar: 53
Fiscal: 27
month = 0
various week stuff for date: 20100101
Week of Year
Calendar: 1
Fiscal: 27
disconnected


Hope that helps!