Amitoj,
It took me a while to get this working for me (my week starts on Sunday) but everything is testing out as expected now.
Here is my Javascript rule text for returning the week number given a date. Note the date needs to be formatted as yyyy-MM-dd as indicated in the screenshot above.
function getWeekNum(dt) {
// Convert the date string to a date object
var parts = dt.split('-');
var d = new Date(parts[0],parts[1]-1,parts[2]);
// Make Sunday's day number 1 (Week Starts on Sunday)
var weekShift = 1; // Shift the start of the week by 1 since getDay for Sunday = 0
// Set to nearest Thursday: current date + 4 - current day number
d.setDate(d.getDate() + 4 - ((d.getDay()+weekShift)||7));
// Get first day of year
var yearStart = new Date(d.getFullYear(),0,4);
// Calculate full weeks to nearest Thursday
var weekNo = Math.ceil((((d - yearStart) / 86400000) + 1)/7)
// Return array of year and week number
return weekNo;
}
getWeekNum(argv[0]);
--Bill