0

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

3 Answers 3

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

prevDate.setDate ( curDate.getDate() - 7 );
2
  • Hi It shows the difference of date only. For example Today's date is 1. This function gives the output as -6. but the need is 26/01/2010 to 01/02/2010
    – susanthosh
    Feb 1, 2010 at 10:26
  • if (sValue == "lastweek") { var cdate = new Date(); var dateString = cdate.getMonth() + "/" + cdate.getDate() + "/" + cdate.getFullYear() + " " var pdate = cdate.setDate(cdate.getDate() - 7); alert(pdate); radTRStart.set_SelectedDate = pdate.format("mm/dd/yyyy"); Use this script function any dropdown selected change event. You will come to know the difficulty.
    – susanthosh
    Feb 1, 2010 at 12:14
0

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
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.