0

shipout_day_from = 2

shipout_day_to = 3

If shipout_day_from is Sunday then add +1 day to shipout_day_from & shipout_day_to

If shipout_day_to is Sunday then add +1 day to shipout_day_to. (shipout_day_from wont add +1 day)

<div class="shipout">
<p id="postage">Postage: <span id="postage-msg">FREE (UK MAINLAND)</span></p>
<span id="shipout-title"></span><span id="shipout-date"></span>
<script>
Date.prototype.addDays = function(days) {
  var dat = new Date(this.valueOf());
  locale = "en-us";
  dat.setDate(dat.getDate() + days);
  var curr_date = dat.getDate();
//Changes Start
  var day = dat.getDay();
  if(dat.toLocaleString(locale, { weekday: "long" }) == 'Sunday'){
    curr_date = curr_date + 1;
    day = day + 1;
  }
//Changes End
  var s=["th","st","nd","rd"];
  v= curr_date %100;

  var curr_month = dat.toLocaleString(locale, { month: "long" });
  return curr_date + (s[(v-20)%10]||s[v]||s[0]) + " " + curr_month + " " + "(" + ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][day] +")";
}

var dat = new Date();

document.getElementById("shipout-title").innerHTML = "Estimated Delivery: "
document.getElementById("shipout-date").innerHTML =  dat.addDays(<?php echo $_product->getData('shipout_day_from');?>) + " - " + dat.addDays(<?php echo $_product->getData('shipout_day_to')

</script>
</div>

As of current Script the Output will be Estimated Delivery: 25th March (Sat) - 27th March (Mon) If today is 23rd March Thursday. (Adding +1 day to the TO DATE successfully).

But

As of current Script the Output will be Estimated Delivery: 27th March (Mon) - 27th March (Mon) If today is 24th March Friday. (Adding +1 day to the From Date but the TO DATE remains same.)

I need the output like Estimated Delivery: 27th March (Mon) - 28th March (Tue) If today is 24th March Friday.

1

FINALLY!! check out below code.

<div class="shipout">
<p id="postage">Postage: <span id="postage-msg">FREE (UK MAINLAND)</span></p>
<span id="shipout-title"></span><span id="shipout-date"></span>
<script>
var flag = false;;
Date.prototype.addDays = function(days) {
  if(flag == true){
    days = days + 1;
    flag = false;
  }
  var dat = new Date(this.valueOf());
  locale = "en-us";
  dat.setDate(24 + days);
  var curr_date = dat.getDate();

//Changes Start
  var day = dat.getDay();
  if(dat.toLocaleString(locale, { weekday: "long" }) == 'Sunday'){
    curr_date = dat.getDate() + 1;
    day = day + 1;
    flag = true;
  }

//Changes End
  var s=["th","st","nd","rd"];
  v= curr_date %100;

  var curr_month = dat.toLocaleString(locale, { month: "long" });
  return curr_date + (s[(v-20)%10]||s[v]||s[0]) + " " + curr_month + " " + "(" + ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][day] +")";
}

var dat = new Date();

document.getElementById("shipout-title").innerHTML = "Estimated Delivery: "
document.getElementById("shipout-date").innerHTML =  dat.addDays(2) + " - " + dat.addDays(3)

</script>
</div>
  • Great... It works – Doodu Mar 22 '17 at 20:09
  • Plz update the other question too... I will mark as answer there too – Doodu Mar 22 '17 at 20:09
  • your welcome....I updated the another answer too – Abhishek Panchal Mar 22 '17 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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