# For a JS function

How to write a JS function, for example: I want to know that in 2013 June third weeks of starting and ending date?
The argument is a certain period of a week to get dates

Started by Shelley at November 14, 2016 - 7:38 PM

This depends on your 1 week from week 1 is started or Sunday

Posted by Nikita at November 18, 2016 - 7:39 PM

<script type="text/javascript">
function weekDate(ym,n){
var d=new Date(ym.replace(/-/,"/")+"/1");//For each month of 1 date
var b=new Date(d.getTime()+((n-1)*7-d.getDay())*1000*60*60*24);
//new Date(d-d.getDay())The first week of the month start date, and for a week to 7 days + (n-1) *7 can be obtained in the N weeks after the start date
return b.getFullYear()+ "-" + (b.getMonth()+1) + "-" + b.getDate();
}
</script>

Posted by Tom at November 28, 2016 - 8:22 PM

A week from week 1 to start
function getMWD(y,m,w){
var d=new Date([y,m,1].join('/'));
var day= (d.getDay()||7)-1;
var d1,d2
if(w-1){
w=w-2;
w=w<0?0:w
d1=new Date(  d*1+ ( (7-day)+w*7 )*864E5    )
d2=new Date(  d1*1+ 6*864E5    )
}else{
d1=d;
d2=new Date(  d1*1+ (6-day)*864E5    )
}
return [fmt(d1), fmt(d2)];
function fmt(d){ return d.toLocaleDateString().match(/\d+/g).join('-') }
}

var w=getMWD(2013,6,3);

Posted by Nikita at November 30, 2016 - 8:50 PM

The SQL statement is very simple

Posted by Rod at December 11, 2016 - 9:33 PM

function weekDate(ym,n){
n =(n-1)*7+1;
var d = new Date((ym + '/' + n).replace(/-/, '/'));
d.setDate(d.getDate() - d.getDay());
return (d.toLocaleDateString().match(/\d+/g).join('-'));
}

Posted by Natalie at December 14, 2016 - 9:57 PM

+1
The 2 floor of the code when it comes to the key, this premise is not sure how to write code

Posted by Channing at December 25, 2016 - 10:43 PM