-1

Please anyone share the code to find the previous week's first date from current date in JavaScript. For example, if the current date is 19th dec 2012, I should get 10th Dec 2012 and last date 16th Dec 2012 as result.

VisioN
  • 143,310
  • 32
  • 282
  • 281
crickpatel0024
  • 1,999
  • 6
  • 30
  • 47

1 Answers1

1
function getPreviousSunday()
{
var today=new Date();
return new Date().setDate(today.getDate()-today.getDay()-7);
}


function getPreviousMonday()
{
var today=new Date();
if(today.getDay() != 0)
  return new Date().setDate(today.getDate()-7-6);
else
  return new Date().setDate(today.getDate()-today.getDay()-6);
}
Nipun Jain
  • 626
  • 4
  • 6