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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:50:49+00:00 2026-05-23T11:50:49+00:00

Is there any way in JavaScript that I can check if date is between

  • 0

Is there any way in JavaScript that I can check if date is between 2 dates?

I have an array like

var unavailableDates = ["5-7-2011","6-7-2011","7-7-2011","15-7-2011","16-7-2011","17-7-2011" ];

and now I have 2 dates like 1-7-2011 and 10-7-2011. I want to see if any value from unavailableDates falls between these date. If it falls it should return alert.

Can someone help me on this? I am in process of learning more about JavaScript and jQuery. I am not able to code it the way I understood the problem.

  • 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-23T11:50:50+00:00Added an answer on May 23, 2026 at 11:50 am

    Here you have the solution

    var unavailableDates = ["5-7-2011","6-7-2011","7-7-2011","15-7-2011","16-7-2011","17-7-2011" ];
    function str2date(sdate){ //This function gets a string and return a Date object
       var parts = sdate.split("-");
       return new Date(parts[2], parseInt(parts[1], 10)-1, parts[0]);
    }
    var stamp1 = str2date("1-7-2011").getTime(); //First date. getTime() converts it to an integer
    var stamp2 = str2date("10-7-2011").getTime(); //Second date
    for(var i=0; i<unavailableDates.length; i++){
       var curStamp = str2date(unavailableDates[i]).getTime();
       if(curStamp >= stamp1 && curStamp <= stamp2) //Check if it falls in range
           alert(unavailableDates[i] + " falls in range");
    }
    

    Hope this helps. Cheers

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

Sidebar

Related Questions

Is there any way that I can call a JavaScript function via css? For
Is there any other way to write javascript:false that is more pleasant? I'm building
Is there any way I can make Firefox call a JavaScript function in my
Is there any way to get the source line number in Javascript, like __LINE__
Is there any way to execute arbitrary code in Flash, like javascript's eval()? I'd
Just like in JavaScript : opener.document.getElementByName jQuery: ?? Is there any way to get
In javascript, is there any different between these two: // call MyFunction normal way
Is there any way to periodically check a database in PHP or JavaScript? I
Is there any way in JavaScript to create a "weak reference" to another object?
Is there any way to follow a URL in JavaScript without setting the document.location.href

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.