Results 1 to 2 of 2

Thread: jQuery - Week dropdown for a paricular month

  1. #1
    Join Date
    Jul 2013

    jQuery - Week dropdown for a paricular month

    I am using jquery-week-calendar-master to customize as par my need. I need to show a dropdown of weeks in a particular month
    1st week
    2nd week
    3rd week
    and so far

    and by default the current week selected, here is my code... but some wrong there

    var currdate = options.date;
    var firstDay = new Date(currdate).getDay();
    var totalDays = new Date(currdate.getFullYear(), currdate.getMonth() + 1, 0).getDate();
    var totWeeks = Math.ceil((firstDay + totalDays) / 7);
    var weekNum = 0 | currdate.getDate() / 7;
    var currentWeek = ( currdate.getDate() % 7 === 0 ) ? weekNum - 1 : weekNum;
    var weekOptions='';
    for(var i=0; i<totWeeks; i++) {
    var currentWeekIndex = currentWeek-1;
    weekOptions += '<option value="'+i+'">&lt;'+month + ' - ' +self._getWeekName(i)+'&gt;</option>';

    $calendarContainer.find(".selectWeekOfMonth").change(function() {
    self.goToWeek($(this).val(), currentWeekIndex);
    return false;

    Also another problem is if for any month, it starts midweek, the week shows half...
    The calendar first day of week starts from Monday
    For example Sep 2013, starts from Saturday and 1st week shows
    only 1
    then 2-8
    and 30

    so here the week shows 6 but total no of week is 5

    Please help! Its urgent

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    A method is to work with ISOweeks numbers
    <script language="javascript" type="text/javascript">
    Date.prototype.getISOWeek = function() {var i,d,firstWeekMonday;
        var i=1;while (new Date(this.getFullYear(),0,i).getDay()!=4) ++i;// i the first Thursday;
        var firstWeekMonday = new Date(this.getFullYear(),0,i-3,0,0,0,-1);// one millisecond before 
            if (d==53 && new Date(this.getFullYear(),0,1).getDay()!=4 && new Date(this.getFullYear()+1,0,0).getDay()!=4) d=1;    
        return d?d:new Date(this.getFullYear(),0,0).getISOWeek();// the week of the 31 December before if d is null !
    var i,d,c='<p>';
    d=1;while (new Date(year,0,d).getDay()!=1) --d;
    for (i=d-7;i<15000;i+=7)  {
        d=new Date(year,0,i,0,30,0);e=new Date(year,0,i,0,-30,0);
        c+=d.toLocaleString()+' <b>Week '+d.getISOWeek()+'</b> after '+e.toLocaleString()+' <b> Week '+e.getISOWeek()+'</b><br>';}
    var tdy=new Date();
    But take care. There is many bad script on the web about this question !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center