Given say 2013 and 38 (38 = 38th week of the year) I want to get 2013-09-16. Is there a Javascript or jQuery function?
Note: the week of year is based on ISO week day calendar. i. e. given 2014 and 1, I need to get 2013-12-30
Given say 2013 and 38 (38 = 38th week of the year) I want to get 2013-09-16. Is there a Javascript or jQuery function?
Note: the week of year is based on ISO week day calendar. i. e. given 2014 and 1, I need to get 2013-12-30
Using the answer from here Get friday from week number and year in javascript you will get your excepted answer
var w2date = function(year, wn){
var Day10 = new Date( year,0,10,12,0,0),
Day4 = new Date( year,0,4,12,0,0),
weekmSec = Day4.getTime() - Day10.getDay() * 86400000; // 7 days in milli sec
return new Date(weekmSec + ((wn - 1) * 7 ) * 86400000);
};
w2date(year, week);
calculating total milli seconds of the given week count (weekmSec + ((wn - 1) * 7 ) * 86400000
) and then passing it to Date object will give you the expected answer
Use a library like momentjs
var year = 2013, weeks = 38;
var m = moment("01-01-" + year, "DD-MM-YYYY");
m.add('weeks', weeks - 1)
console.log(m.toDate())
Demo: Fiddle
Using js
var year = 2013, weeks = 38;
var d = new Date(year, 0, 1);
d.setDate((weeks - 1) * 7)
Demo: Fiddle
Try this snippet of code:
var d = new Date("January 1, 2013 00:00:00");
d.setDate(259);
alert(d);
259 represents 37 weeks * 7.
Hope this helps