Skip to content Skip to sidebar Skip to footer

Datepicker Limit Current Year

I have a little problem with datepicker, I'd want that a user with arrows can only select a date between the first day of the first month and the last day of the month, but it woul

Solution 1:

Set minDate and maxDate like

$(function() {
    var year = (newDate).getFullYear();
    $( "#datepicker" ).datepicker({
        minDate: newDate(year, 0, 1),
        maxDate: newDate(year, 11, 31)
    });
});

Link

Solution 2:

Just use yearRange like this:

datepick({yearRange: new Date().getFullYear() + ':' + new Date().getFullYear()});

Solution 3:

Why not mention the yearRange to be currentyear : currentyear?

You can do this: after

$(document).ready(function(){
var curyear = $("#year").text( (newDate).getFullYear() );

Inside your datepicker, yearRange: "+curyear+":"+curyear+"

Solution 4:

This will work for you:

jsFiddle

<head><metacharset="utf-8" /><linkhref="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /><scriptsrc="http://code.jquery.com/jquery-1.9.1.js"></script><scriptsrc="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script><linkhref="/resources/demos/style.css" /><script>

    $(document).ready(function() {

        var date = newDate(), y = date.getFullYear(), m = date.getMonth();
        var fSDate = newDate(y, m, 1);
        var fEDate = newDate(y, m + 1, 0);

        $.datepicker.setDefaults({
            changeMonth: false,
            changeYear: false,
            showOtherMonths: false,
            yearRange: '-0:+0',
            dateFormat: 'yy-mm-dd',
            defaultDate: +0,
            numberOfMonths: 1,
            minDate: fSDate, 
            maxDate: fEDate,
            showAnim: 'fadeIn',
            showButtonPanel: false
        });

        $('#date_start').datepicker();

    }); //END document.ready()</script></head><body><inputtype="text"id="date_start"></body></html>

Post a Comment for "Datepicker Limit Current Year"