Hey,
There have been alot of snippets that deal with getting the week of a year. But has anyone ever come up with a week of the month?
Kendall
javascript week for month
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Re: javascript week for month
didnt workkaszu wrote:Google returned http://www.webdeveloper.com/forum/archi ... -2289.html
Re: javascript week for month
Wrote my own function:
Code: Select all
function getWeekOfMonth(now) {
var todayDayOfMonth = now.getDate() - 1;
var first = new Date(now.getFullYear() + '/' + (now.getMonth() + 1) + '/01');
var monthFirstDateDay = first.getDay();
return Math.ceil((todayDayOfMonth + monthFirstDateDay) / 7);
}
for(var i=1; i<10; i++)
document.write('2008/05/0' + i + ': ' + getWeekOfMonth(new Date('2008/05/0' + i)) + '<br />');
for(var i=10; i<32; i++)
document.write('2008/05/' + i + ': ' + getWeekOfMonth(new Date('2008/05/' + i)) + '<br />');