(function($) { "use strict"; var date_format = "d.m.yyyy"; $.get("/api/getvars/").done(function(data) { date_format = data["date_format"]; }); $('.dpd1').each(function() { console.log(date_format); var mindate = new Date($(this).attr("data-mindate")); mindate = new Date(mindate.getFullYear(), mindate.getMonth(), mindate.getDate(), 0, 0, 0, 0) var maxdate = new Date($(this).attr("data-maxdate")); maxdate = new Date(maxdate.getFullYear(), maxdate.getMonth(), maxdate.getDate(), 0, 0, 0, 0) var checkin = $(this).datepicker({ format: date_format, onRender: function(date) { return ((date.valueOf() < mindate.valueOf()) || (date.valueOf() > maxdate.valueOf())) ? 'disabled' : ''; } }).on('changeDate', function(ev) { checkin.hide(); }).data('datepicker'); }); })(jQuery);