Sunday, November 18, 2012

Sharepoint 2010 - Get Work Week

Sharepoint 2010 - Get Work Week

Excellent post on getting the Work Week or Week of Year from http://joranmarkx.wordpress.com/2011/12/09/use-the-calculated-field-to-show-weeknumber-in-sharepoint-2010/

For my own notes only, no plagiarism intended.

Work Week calculation:

If the work week starts from the Monday of the week that contains the first Thursday of the year:
=INT(([datecolumn]-DATE(YEAR([datecolumn]-WEEKDAY([datecolumn]-1)+4),1,3)+WEEKDAY(DATE(YEAR([datecolumn]-WEEKDAY(datecolumn-1)+4),1,3))+5)/7)

If the work week starts from the Monday of the week that contains the first Monday of the year:
=INT(([datecolumn]-DATE(YEAR([datecolumn]-WEEKDAY([datecolumn]-1)+4),1,3)+WEEKDAY(DATE(YEAR([datecolumn]-WEEKDAY(datecolumn-1)+4),1,3))+1)/7)

-Calculate the distance between the beginning of the year (with regard of the start of week 1) to the datecolumn
-Add the day of the week of the 1st January of the datecolumn year added with 5 (Thursday)
-Divide by number of days in a week
-Floor by doing a cast to INT

If week 1 starts in the week of the 1st January (USA Standards):
=INT(([datecolumn]-DATE(YEAR([datecolumn]),1,1)+(TEXT(WEEKDAY(DATE(YEAR([datecolumn]),1,1)),"d")))/7)+1

-Calculate the distance between the beginning of the year to the datecolumn
-Add day of the week of the 1st January of the datecolumn year
-Add divide by number of days in a week
-Cast to integer (is Floor)
-Add one day

Related Posts Plugin for WordPress, Blogger...