Monday, 29 May 2017

Ionic Datepicker With date range

No comments
var todayDate = new Date();
    todayDate.setFullYear(todayDate.getFullYear() - 90);
    $scope.getAge = function (DOB) {
        var today = new Date();
        var birthDate = new Date(DOB);
        var age = today.getFullYear() - birthDate.getFullYear();
        var m = today.getMonth() - birthDate.getMonth();
        if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
            age--;
        }
        return age;
    }
  var objFromDate = {
        callback: function (val) {
            var output = $scope.getAge(val);
            if (output < 18 || output > 99) {
                alert("User age should be between 18 years to 99 years.");
                return;
            }          
           $scope.profile.Birth_date = $filter('date')(new Date(val), 'MM/dd/yyyy');
        },
        inputDate: new Date(),
        mondayFirst: true,
        templateType: 'popup',
        showTodayButton: false,
        from: todayDate,
        to: new Date(),
        dateFormat: 'MM/dd/yyyy',
        closeOnSelect: false,
    };
    $scope.dobDatePicker = function () {
        ionicDatePicker.openDatePicker(objFromDate);
    };