JavaScript subtract 1 week from current date - javascript subtract week from date,subtract week from date excel,subtract

This is how I am getting current date, dd-MMM-yyyy format. How do I subtract 1 week.

    var m_names = new Array("JAN", "FEB", "MAR",
            "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");

    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();
    var current = curr_date + "-" + m_names[curr_month] + "-" + curr_year;
Answer:1

Just add d.setDate(d.getDate() - 7); after your var d = new Date();

 var m_names = new Array("JAN", "FEB", "MAR",
     "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
 var d = new Date();
 d.setDate(d.getDate() - 7);
 var curr_date = d.getDate();
 var curr_month = d.getMonth();
 var curr_year = d.getFullYear();
 var current = curr_date + "-" + m_names[curr_month] + "-" + curr_year;

jsFiddle example

Answer:2

With moment.js, given that

moment().calendar();

is

Today at 10:27 AM

then all you need is

moment().subtract('days', 7).format('DD-MMM-YYYY')

which becomes

06-Nov-2013
Answer:3

You may try like this:-

var d= new Date();
d.setDate(d.getDate() - 7);

Using Date.js you can do like this:

Date.parse("t - 7 d").toString("MM-dd-yyyy");     
Date.today().addDays(-7).toString("MM-dd-yyyy");  
Date.today().addWeeks(-1).toString("MM-dd-yyyy");
Answer:4

I am trying to get a attribute value from my dom element, but i am getting result as: Uncaught TypeError: Object #<HTMLDivElement> has no method 'attr' I am not able to get the attribute ...

I am trying to get a attribute value from my dom element, but i am getting result as: Uncaught TypeError: Object #<HTMLDivElement> has no method 'attr' I am not able to get the attribute ...

  1. unable to return dimension attribute value

I have the following; var room = function(){ this.entities = new Array(); } var myRoom = new room(); I also have a bunch of entites like this; var entity = function(){ this.title = "A ...

I have the following; var room = function(){ this.entities = new Array(); } var myRoom = new room(); I also have a bunch of entites like this; var entity = function(){ this.title = "A ...

  1. filter array objects javascript
  2. filter array objects angular 6
  3. filter array objects
  4. filter array objects js
  5. filter array objects swift
  6. filter array objects jquery
  7. filter array objects angularjs
  8. filter array objects lodash
  9. filter array objects angular2
  10. array filter objects php
  11. filter array of objects by property
  12. filter array of objects typescript
  13. filter array of objects javascript es6
  14. filter array of objects by property javascript
  15. filter array of objects javascript by key
  16. filter array of objects by key
  17. filter array of objects by key value
  18. filter array of objects javascript by value
  19. filter array of objects based on property
  20. filter array of objects javascript based on property

Apologies if this sounds totally stupid but I'm a total dunce when it comes to coding! I'm trying to make a higher or lower guessing game using a deck of cards (i.e. The player guesses if the next ...

Apologies if this sounds totally stupid but I'm a total dunce when it comes to coding! I'm trying to make a higher or lower guessing game using a deck of cards (i.e. The player guesses if the next ...

I want to attached function on click event on document. My function is attached it but it is calling it also. I don't understand why. Demo $(function () { $('a').click(function () { $(...

I want to attached function on click event on document. My function is attached it but it is calling it also. I don't understand why. Demo $(function () { $('a').click(function () { $(...