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

  • SEARCH
  • Home
  • 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 7708941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:44:24+00:00 2026-06-01T00:44:24+00:00

I am trying to create a date object that is 90 days from a

  • 0

I am trying to create a date object that is 90 days from a specified date for use in a date comparison, but am not getting the correct dates. I have isolated my problem to the code shown below.

var now = new Date();
var beforeNow = new Date();
var afterNow = new Date();
var myDate = new Date();
var beforeMyDate = new Date();
var afterMyDate = new Date();

beforeNow.setDate(now.getDate() - 90);
afterNow.setDate(now.getDate() + 90);

myDate.setFullYear(2011, 10, 22); // set to Nov 22, 2011

beforeMyDate.setDate(myDate.getDate() - 90); // set to 90 days before Nov 22, 2011
afterMyDate.setDate(myDate.getDate() + 90); // set to 90 days after Nov 22, 2011

The above is resulting in:

beforeMyDate: Fri Dec 23 2011 08:46:18 GMT-0800 (Pacific Standard Time)

myDate: Tue Nov 22 2011 08:46:18 GMT-0800 (Pacific Standard Time)

afterMyDate: Wed Jun 20 2012 08:46:18 GMT-0700 (Pacific Daylight Time)

Here’s a fiddle: http://jsfiddle.net/LnmpR/9/

Any help would be appreciated. Thanks.

  • 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-06-01T00:44:26+00:00Added an answer on June 1, 2026 at 12:44 am

    You have to pass the same base time to the beforeMyDate and afterMyDate Date instances. Currently, you’re adding/removing 90 days of the current date (new Date() without parameters returns the current time).

    Demo: http://jsfiddle.net/LnmpR/12/

    var now = new Date();
    var beforeNow = new Date();
    var afterNow = new Date();
    var myDate = new Date();
    var beforeMyDate;
    var afterMyDate;
    
    beforeNow.setDate(now.getDate() - 90);
    afterNow.setDate(now.getDate() + 90);
    
    myDate.setFullYear(2011, 10, 22);    // set to Nov 22, 2011
    beforeMyDate = new Date(myDate);     // Set base to myDate
    afterMyDate = new Date(myDate);      // Set base to myDate
    
    beforeMyDate.setDate(myDate.getDate() - 90); // set to 90 days before Nov 22, 2011
    afterMyDate.setDate(myDate.getDate() + 90); // set to 90 days after Nov 22, 2011
    

    The values of beforeNow and afterNow might also be off by a few milliseconds, because all of them are new, parameterless instances of the Date object.

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

Sidebar

Related Questions

Hy! I'm trying to create a list of days(integer) from a list of dates(date).
I am trying to create a new date object from string as follows: var
I am trying to create a Date object from an input String. The code
I am trying to create an HTML5 input date component so that I can
I am trying to create a select list starting from the current date of
I'm trying to create a simple date class, but I get an error on
I'm trying to make a query function that accepts two datetime.date object(start_date and end_date),
I am trying to create a list of birth days, ordered by the dates,
I'm not sure if this is possible, but I'm trying to use the C#
I'm trying to create a shared object (.so) that will make it so, by

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.