Welcome to Snipped, a code gallery for creating, saving and sharing all kinds of code snippets.

jQuery Current Week Number

jQuery · February 16, 2017 6:36 pm

0 0 113

Get the current week number using jQuery.

// jQuery:
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
var dayOfYear = ((today - onejan +1)/86400000);
return Math.ceil(dayOfYear/7)
};


jQuery(function(){
var today = new Date();
var weekno = today.getWeek();
$("#weekNo").html(weekno);
});

// HTML:
<div id="weekNo"></div>

Discuss this Snip
    No Discussion Comments found.

    You must be Signed In to discuss this Snip
Snipped

Snipped

Joined on
February 16, 2017

  • 9 Snips
    Contributed
  • 0 Likes
    Given
  • 0 Comments Posted
Snip Tags
Get Social And Share

Manage and share all of your code snippets in one easy place.