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 5949553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:15:58+00:00 2026-05-22T17:15:58+00:00

Possible Duplicate: Get difference between 2 dates in javascript? I am storing date variables

  • 0

Possible Duplicate:
Get difference between 2 dates in javascript?

I am storing date variables like this:

var startYear = 2011;
var startMonth = 2;
var startDay = 14;

Now I want to check if current day (today) is falling within 30 days of the start date or not.
Can I do this?

var todayDate = new Date();
var startDate = new Date(startYear, startMonth, startDay+1);
var difference = todayDate - startDate;

????

I am not sure if this is syntactically or logically correct.

  • 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-22T17:15:58+00:00Added an answer on May 22, 2026 at 5:15 pm

    In JavaScript, the best way to get the timespan between two dates is to get their “time” value (number of milliseconds since the epoch) and convert that into the desired units. Here is a function to get the number of days between two dates:

    var numDaysBetween = function(d1, d2) {
      var diff = Math.abs(d1.getTime() - d2.getTime());
      return diff / (1000 * 60 * 60 * 24);
    };
    
    var d1 = new Date(2011, 0, 1); // Jan 1, 2011
    var d2 = new Date(2011, 0, 2); // Jan 2, 2011
    numDaysBetween(d1, d2); // => 1
    var d3 = new Date(2010, 0, 1); // Jan 1, 2010
    numDaysBetween(d1, d3); // => 365
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to calculate difference between two dates using java I'm trying something
Possible Duplicates: Difference between dates How to calculate the date difference between 2 dates
Possible Duplicate: How to Get time difference in iPhone I´m getting date and time
Possible Duplicate: Calculating the Difference Between Two Java Date Instances time1: 17:05 time2: 17:08
Possible Duplicate: jQuery ajax() vs get()/post() what is the difference between jQuery ajax() and
Possible Duplicate: What's the difference between a URI and a URL? Just to get
Possible Duplicate: What's the difference between is_null($var) and ($var === null)? PHP has two
Possible Duplicate: Get all files from VSS for a given date? I need to
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of

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.