susanthosh
susanthosh

Reputation: 450

Date manipulations in Javascript

I am using a dropdownlist and a calendar control in my page. In that I am having following list items. 1)Last Week 2)last month

If I choose last week in the dropdownlist the calendar control should display the date range from date 7 days ago and today's date. How can I get it through Java Script

Upvotes: 0

Views: 3876

Answers (3)

YOU
YOU

Reputation: 123791

How about using DateJS library?

Its return

  • 7 days ago => Monday, January 25, 2010 12:00:00 AM
  • last week => Monday, January 25, 2010 12:00:00 AM
  • last month => Friday, January 01, 2010 12:00:00 AM

Upvotes: 0

rahul
rahul

Reputation: 187020

var curDate = new Date();
var prevDate = new Date();

prevDate.setDate ( curDate.getDate() - 7 );

Upvotes: 1

RaYell
RaYell

Reputation: 70414

// current date
var now = new Date();
// 7 days earlier
now.setDate(now.getDate()-7);

Upvotes: 11

Related Questions