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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:36:09+00:00 2026-06-01T13:36:09+00:00

I updated my code with string dates created with new Date and added back

  • 0

I updated my code with string dates created with new Date and added back in the if statement. This isn’t disabling the string or range though. I’ve added the datepicker code too.

function unavailableDays(date) {

function createDateRange(first, last) {
    var dates = [];
    for(var j = first; j < last; j.setDate(j.getDate() + 7)) {
        dates.push(new Date(j.getTime()));
    }
    var alwaysDisabled = [new Date("1963-3-10T00:00:00"), new Date("1963-3-17T00:00:00"), new Date("1963-3-24T00:00:00"), new Date("1963-3-31T00:00:00"), new Date("1965-9-18T00:00:00")];
    return dates.concat(alwaysDisabled);
}

var disabledDays = createDateRange(new Date("1978-8-10T00:00:00"), new Date("1978-11-5T00:00:00"));

var yy = date.getFullYear(), mm  = date.getMonth(), dd = date.getDate();
    for (i = 0; i < disabledDays.length; i++) {
    if($.inArray(yy + '-' + (mm+1) + '-' + dd,disabledDays) != -1 || new Date() < date) {
        return [false];
    }
}
    return [true];
}

$(document).ready(function (){
$('.selector').datepicker({
    inline: true,
    dateFormat: 'yy-mm-dd',
    constrainInput: true,
    changeYear: true,
    changeMonth: true,
    minDate: new Date(1940, 1-1, 1),
    maxDate: new Date(2011, 10-1, 24),
    beforeShowDay: unavailableDays,    
    onSelect: function(dateText, inst) {
            $("#img").attr("src", "http://www.example.com" + dateText + ".jpg"); 
         var chosenDates = $.datepicker.parseDate('yy-mm-dd', dateText);
         var backToString = $.datepicker.formatDate('MM dd' + ',' + ' yy', chosenDates);
         $('.info').html('You are viewing:' + '<br />' +
             backToString).addClass('background'); 
    } 
});

});

  • 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-01T13:36:10+00:00Added an answer on June 1, 2026 at 1:36 pm

    There is no problem in having a function inside of another, JavaScript is pretty much based on that. You could also have separate functions, and it would work as well.

    UPDATE

    (Considering the date versus dates issue is fixed)

    Here is what seems to be the problem (this is what your question seems to be really about, not functions inside of functions!): createDateRange returns an array of Date objects, but your other version (var disabledDays = ["1963-3-10", ...) is an array of strings (and in a format that cannot be parsed by new Date(str)).

    Your current loop seems to be trying to deal with the this string version, and it works, but you want to createDateRange to always ignore certain dates (as far as I understand what you are saying). So, try this:

    function unavailableDays(date) {
    
        function createDateRange(first, last) {
            var dates = [];
            for(var j = first; j < last; j.setDate(j.getDate() + 7)) {
                dates.push(new Date(j.getTime()));
            }
            var alwaysDisabled = [new Date("1963-03-10T00:00:00"), new Date("1963-03-17T00:00:00"), new Date("1963-03-24T00:00:00"), new Date("1963-03-31T00:00:00"), new Date("1965-09-18T00:00:00")];
            return dates.concat(alwaysDisabled);
        }
    
        var disabledDays = createDateRange(new Date("1978-08-10T00:00:00"), new Date("1978-11-05T00:00:00"));
        for (i = 0; i < disabledDays.length; i++) {
            if(disabledDays[i].getTime() == date.getTime()) {
                return false;
            }
        }
        return true;
    
    }
    
    // Use `T00:00:00` after the date to set it as GMT, or
    // dates can be interpreted as the previous day on some timezones.
    var testDate1 = new Date('1978-08-10T00:00:00')
    console.log("-- " + unavailableDays(testDate1)); // false
    var testDate2 = new Date('1978-08-11T00:00:00')
    console.log("-- " + unavailableDays(testDate2)); // true
    var testDate3 = new Date('1978-08-17T00:00:00')
    console.log("-- " + unavailableDays(testDate3)); // false
    var testDate4 = new Date('1963-03-10T00:00:00')
    console.log("-- " + unavailableDays(testDate4)); // false
    

    http://jsfiddle.net/t4ahF/4/

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

Sidebar

Related Questions

Okay I have updated my code quite a bit. I am getting a new
I've updated my code here. I've put the range inside the unavailableDays function which
I am new android and I would appreciate some help. I have this code:
I have updated code for ActiveX functionality which already installed on client(in their Windows
I updated my code like Andro wrote about to me: public class ZiiziiActivity extends
Okay I have updated my code a little, but I am still not exactly
I've updated some code to use the Ajax Control toolkit 0911 beta and for
UPDATE I have updated my code in response to @MichaelRushton comments. I am now
I ran some CUDA code that updated an array of floats. I have a
Code is read more often then updated. Writing more readable code is better than

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.