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

8
  • try this way.. magento.stackexchange.com/a/33536/68695 Commented Mar 14, 2019 at 13:31
  • i will try and update u @rakesh Commented Mar 14, 2019 at 13:34
  • its not working for me Commented Mar 14, 2019 at 13:38
  • beforeShowDay? Are you using a jQuery Datepicker widget? Otherwise dateStatusFunc should be correct imho.
    – HelgeB
    Commented Mar 14, 2019 at 17:02
  • I was tried it your info but it was not working for me @HelgeB Commented Mar 15, 2019 at 5:10

2 Answers 2

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];
     }
     }

    }
6
  • you have which code apply? Commented Mar 15, 2019 at 6:08
  • i tried a second way it gives error prnt.sc/my4g78 Commented Mar 15, 2019 at 6:11
  • i have tested first way working for me Commented Mar 15, 2019 at 6:16
  • i tried both way 1st one shows nothing 2nd one reflects prnt.sc/my4g78 Commented Mar 15, 2019 at 6:23
  • s i have change the format Commented Mar 15, 2019 at 6:27
2

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>
3
  • my second way is right only date formate wrong Commented Mar 15, 2019 at 11:05
  • yes @rakesh i accept your answer Commented Mar 15, 2019 at 11:30
  • thanks @divya my pleasure!! Commented Mar 15, 2019 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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