Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:50:16+00:00 2026-05-27T15:50:16+00:00

I’m trying to get the past X days counting from today back using JavaScript.

  • 0

I’m trying to get the past X days counting from today back using JavaScript.

However I’m only able to work out how to get today’s date but now the previous dates.

Say If I wanted the last 6 days including today, it to be printed as such:

  • Monday Nov 5
  • Sunday Nov 4
  • Saturday Nov 3
  • Friday Nov 2
  • Thursday Nov 1
  • Wednesday Oct 31

Heres what I’ve got so far to get the current day.

(function() {
    var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
        months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
    Date.prototype.getMonthName = function() {
        return months[this.getMonth()];
    };
    Date.prototype.getDayName = function() {
        return days[this.getDay()];
    };
})();

var todayDate = new Date(),
      day = todayDate.getDate(),
      weekday = todayDate.getDayName(),
      month = todayDate.getMonthName(),
      today = weekday + ' ' + month + ' ' + day;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:50:16+00:00Added an answer on May 27, 2026 at 3:50 pm

    using 86400000(miliseconds) approach will have a problem with daylight savings time

    suppose

    var d = new Date(“23/12/2012 00:00:00”);

    var e = new Date(d.getTime() – 86400000);

    and DST is +1 then e will be 23/12/2012 01:00:00

    to solve this you can have a function to calculate the date before like:

    Date.prototype.getPreviousDate = function(beforeDays) {
        if (!days) { beforeDays = 0 }
        return new Date(new Date().setDate(this.getDate() - beforeDays));
    }
    

    then you can use it like

    var todayDate = new Date(), c = 0;

    while(c > 6){
    
      var d = todayDate.getPreviousDate(c),
      day = d.getDate(),
      weekday = d.getDayName(),
      month = d.getMonthName(),
      today = weekday + ' ' + month + ' ' + day;
      alert(today);
    
    
    }
    

    for more details refer to this question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.