I have DateJS set up on my website to give users the ability to know when they will receive their package.
I am utilizing DateJS script to do this.
I need to modify the script so that it does not include weekends when estimating the delivery day.
For example, today (Friday), if someone selects one of the following:
Next Day Air: it should show Monday, not Saturday Two Day Air: It should show Tuesday, not Sunday Three Day Air: It should show Wednesday, not Monday
Help is greatly appreciated.
<div class="panel-body">
<table class="table table-striped">
<thead>
<th>Shipping Method</th>
<th>Estimated Delivery</th>
</thead>
<tbody>
<tr>
<td>3 Day Select</td>
<td><span class="fromDate-1"></span>
<script>
var fromDate = Date.today().addDays(3);
if (fromDate.is().saturday() || fromDate.is().sunday())
fromDate = fromDate.next().monday();
$('.fromDate-1').html(fromDate.toString('dddd MMMM dS'));
</script>
</td>
</tr>
<tr>
<td>2nd Day Air</td>
<td><span class="fromDate-2"></span>
<script>
var fromDate = Date.today().addDays(2);
if (fromDate.is().saturday(1) || fromDate.is().sunday())
fromDate = fromDate.next().monday();
$('.fromDate-2').html(fromDate.toString('dddd MMMM dS'));
</script>
</td>
</tr>
<tr>
<td>Next Day Air</td>
<td>
<span class="fromDate-3"></span>
<script>
var fromDate = Date.today().addDays(1);
if (fromDate.is().saturday() || fromDate.is().sunday())
fromDate = fromDate.next().monday();
$('.fromDate-3').html(fromDate.toString('dddd MMMM dS'));
</script>
</td>
</tr>
</tbody>
</table>
</div>
You're only looking at weekends for the final date after adding days, not looking at weekends as the start or (in the case of 3) in between days. Why not a function like
Then you just need to call that function for each of your spans:
Is that the problem you were trying to solve?