We help IT Professionals succeed at work.

Combining this jquery Date Picker code

curiouswebster
on
I have two sets of code and neeed to combine them. Could someone show me how?

Thanks!

    $(function () {
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            minDate: '-75Y'
        });
    });

//    $(document).ready(function () {
//        function getDateYymmdd(value) {
//            if (value == null) return null;
//            return $.datepicker.parseDate("yy/mm/dd", value);
//        } $('.date').each(function () {
//            var minDate = getDateYymmdd($(this).data("val-rangedate-min"));
//            var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
//            
//            $(this).datepicker({ dateFormat: "dd/mm/yy", minDate: minDate, maxDate: maxDate });
//        });
//    });
Comment
Watch Question

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
$(document).ready(function () {
        function getDateYymmdd(value) {
            if (value == null) return null; 
            return $.datepicker.parseDate("yy/mm/dd", value);
        }
        $('.date').each(function () {
            var minDate = getDateYymmdd($(this).data("val-rangedate-min"));
            var maxDate = getDateYymmdd($(this).data("val-rangedate-max")); 
            
            $(this).datepicker({ dateFormat: "dd/mm/yy", minDate: minDate, maxDate: maxDate,  changeMonth: true, changeYear: true });
        });
 });

Open in new window

curiouswebsterSoftware Engineer

Author

Commented:
What about this:
minDate: '-75Y'

I'd like the min date set automatically to 75 years prior.

curiouswebsterSoftware Engineer

Author

Commented:
And where is the association with "#datepicker"?
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
so remove :
var minDate = getDateYymmdd($(this).data("val-rangedate-min"));
and in bold : $(this).datepicker({ dateFormat: "dd/mm/yy", minDate: minDate, maxDate: maxDate,  changeMonth: true, changeYear: true, minDate: '-75Y' });
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
if you want to apply the first one to only one field :

$(document).ready(function () {
        function getDateYymmdd(value) {
            if (value == null) return null;
            return $.datepicker.parseDate("yy/mm/dd", value);
        }
        $('.date').each(function () {
            var minDate = getDateYymmdd($(this).data("val-rangedate-min"));
            var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
           
            $(this).datepicker({ dateFormat: "dd/mm/yy", minDate: minDate, maxDate: maxDate,  changeMonth: true, changeYear: true });
        });
        $("#datepicker").datepicker({ // apply only to field with ID datepicker
            changeMonth: true,
            changeYear: true,
            minDate: '-75Y'
        });
 })
curiouswebsterSoftware Engineer

Author

Commented:
Thanks!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.