It seems that the fourth of January always is in the first week of a year. If that is correct GAS can help to get the number of the week we are living in.
Very interesting to know.
function getWeekNumber(){ var thisYear = (new Date()).getFullYear(); var fourthDayOfTheYear = new Date(thisYear,0,4); var dayFirstMonday = fourthDayOfTheYear.getDate() + 8 - fourthDayOfTheYear.getDay(); var dateFirstMonday = new Date(thisYear,0,dayFirstMonday); var msFirstMonday = dateFirstMonday.getTime(); var msDateToday = (new Date()).getTime(); var msOneWeek = 7*24*60*60*1000; for(var i=0;i<52;i++){ var msNextMonday = msFirstMonday + (i * msOneWeek); var msComingNextMonday = msNextMonday + msOneWeek; if(msNextMonday <= msDateToday && msDateToday < msComingNextMonday){ var weekNumber = i+2; } } return weekNumber; }
Geen opmerkingen:
Een reactie posten