faqts : Computers : Programming : Languages : JavaScript : Language Core : Dates

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

How can I discover what week it is of a month?

Dec 27th, 2003 13:45
ben joe, jsWalter, http://torres.ws/dev/javascript/index.html


I found it thanx to walter torres at this page : I just modified his 
getWeekOfYear function where I found an error when his function 
computes the beginning of the week (Sunday or Monday)
function _getWeekOfMonth() {
 var strDate = new Date(this);
 var strYear = new Date(strDate.getYear(), strDate.getMonth(), 1)
 /* my "patch" */
 var strDay = (strYear.getDay()) ? strYear.getDay() : 7;
 strYear =  strYear - ( strDay * (24*60*60*1000) );
 return Math.ceil((strDate - strYear) / (7 * 24*60*60*1000));
}
Just add it to Date Object like this :
Date.prototype.getWeekOfMonth = _getWeekOfMonth;
That's all folks !
Abdoulaye CAMARA