3

code:

<script type="text/javascript">
// <![CDATA[
Calendar.setup({
inputField : 'shipping_arrival_date',
ifFormat : '%m-%d-%Y',
showsTime: false,
button : 'shipping_arrival_date_trig',
 align: "Bl",
singleClick : true,
dateStatusFunc : disabledDate,


disableFunc: function(date) {
//disable previous day in datepicker
var now= new Date();
if(date.getFullYear()<now.getFullYear())
{
return true;
}
if(date.getFullYear()==now.getFullYear())
{
if(date.getMonth()<now.getMonth())
{
return true;
}
}
if(date.getMonth()==now.getMonth())
{
if(date.getDate()<now.getDate())
{
return true;
}
}
},
});

function disabledDate(date) {
    var today = new Date();
    return (["3-12-2019", "3-15-2019"].indexOf(date.getDate()) !== -1) ? true : false;
};
// ]]>
</script>

enter image description here

2

try this way...

 function disabledDate(date) {
    var disableddates = ["3-23-2019", "3-20-2019"];

     var m = date.getMonth();
     var d = date.getDate();
     var y = date.getFullYear();

     // First convert the date in to the mm-dd-yyyy format 
     // Take note that we will increment the month count by 1 
     var currentdate = (m + 1) + '-' + d + '-' + y ;

      // We will now check if the date belongs to disableddates array 
     for (var i = 0; i < disableddates.length; i++) {

     // Now check if the current date is in disabled dates array. 
     if ($.inArray(currentdate, disableddates) != -1 ) {
     return [false];
     }
     }

    }
1

Update Answer for disabled dates, day and previous past dates it's working for me

<script type="text/javascript">
    var dayoff = '<?php echo $dayoff; ?>';
// <![CDATA[
Calendar.setup({
inputField : 'shipping_arrival_date',
ifFormat : '%m-%e-%Y',
showsTime: false,
button : 'shipping_arrival_date_trig',
 align: "Bl",
singleClick : true,

disableFunc: function(date) {

               var now = new Date();
                var y = calendar.date.getFullYear();
                var m = calendar.date.getMonth();     
                var d = calendar.date.getDate();
                var day_off_array = dayoff.split(",") ;
                currentTime = new Date();
                var d1=currentTime.getDate();
                var m1=currentTime.getMonth();
                var y1=currentTime.getFullYear();
                var counter = 1;
                var disabledDays = ["3-20-2019", "3-26-2019"];

     var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
      for (i = 0; i < disabledDays.length; i++) {
      var dd = (m+1) + '-' + d + '-' + y;
     if(disabledDays.indexOf(dd) != -1) {
        return true;
       }
    }
                for (var i=0; i<day_off_array.length;i++){
                    if (day_off_array[i]>=0 && day_off_array[i]!=''){
                        if (date.getDay()==day_off_array[i]){
                            if (date.getDate()==currentTime.getDate()){
                                test_flag=true;
                            }
                            return true;
                        }
                    }
                }

                if(y < y1)
                    {
                    return true;
                }
                else if(m1 > m && y==y1)
                    {
                    return true;
                }

            if(date.getFullYear() < now.getFullYear()){
                return true;
            }
            if(date.getFullYear() == now.getFullYear() && date.getMonth() < now.getMonth()){
                return true;
            }
            if(date.getMonth() == now.getMonth() && date.getDate() < now.getDate()){
                return true;
            } 

    }


});
// ]]>
</script>
  • my second way is right only date formate wrong – Rakesh Donga Mar 15 at 11:05
  • yes @rakesh i accept your answer – divya sekar Mar 15 at 11:30
  • thanks @divya my pleasure!! – Rakesh Donga Mar 15 at 11:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.