JQuery UI datepicker using variable to set min date

Hi experts,

I'm using jQuery UI DatePicker on a html page.

I have a date range picker where I'm setting the min date to the first day of the current year and the max day to the last day of the current year.

Here is my fiddle, it works fine.
http://jsfiddle.net/6kqajhdp/


If I have variable like this where I'm storing a year


 $(document).ready(function () {
            //-------------------------

var CalendarYear = 2015;


            //-------------------------
            // end of document ready function
        });

Does anyone know the syntax for the min date and max date properties so that this variable value is used to set the min and max date for the date picker?

So for example if the CalendarYear variable is 2015 then the min date is the January 1 of 2015 and then max date is December 31 of 2015.

So for example if the CalendarYear variable is 2014 then the min date is the January 1 of 2014 and then max date is December 31 of 2014
LVL 1
maqskywalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Try:
var CalendarYear = 2015;
$(document).ready(function () {
            //-------------------------


            // set min date as the first day of the current year
            // set max date as last day in current year

$("#datepicker").datepicker({ minDate: new Date( Date.parse("January 1, "+ CalendarYear) )
                             , maxDate: new Date( Date.parse("December 31, " + CalendarYear) ) 
                            });


            //-------------------------
            // end of document ready function
        });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.