Last active
August 15, 2020 07:46
-
-
Save enamhasan/5cd505f61ada4dac90cbd2923bf130c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ '//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js' | script_tag }} | |
function setShipDate () { | |
// element to write date to | |
var shipdate = document.getElementById("js-ship-date"); | |
// Set start date to today - end date in 2 days | |
var startDate = new Date(); | |
var endDate = "", noOfDaysToAdd = 2, count = 0; | |
// Map numeric month to name | |
var month = new Array(); | |
month[0] = "JAN"; | |
month[1] = "FEB"; | |
month[2] = "MAR"; | |
month[3] = "APR"; | |
month[4] = "MAY"; | |
month[5] = "JUN"; | |
month[6] = "JUL"; | |
month[7] = "AUG"; | |
month[8] = "SEP"; | |
month[9] = "OCT"; | |
month[10] = "NOV"; | |
month[11] = "DEC"; | |
while(count < noOfDaysToAdd){ | |
// add a day to the end date each loop | |
endDate = new Date(startDate.setDate(startDate.getDate() + 1)); | |
// only count when not a weekend | |
if(endDate.getDay() != 0 && endDate.getDay() != 6){ | |
count++; | |
} | |
} | |
// update shipdate HTML | |
shipdate.innerHTML= month[endDate.getMonth()] + ' / ' + endDate.getDate() + ' / ' + endDate.getFullYear(); | |
} | |
setShipDate(); | |
#============ Another way ==================# | |
<p>Order today, and you'll receive your package between <span id="fromDate"></span> and <span id="toDate"></span>.</p> | |
{{ '//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js' | script_tag }} | |
<script> | |
var fromDate = Date.today().addDays(5); | |
if (fromDate.is().saturday() || fromDate.is().sunday()) { | |
fromDate = fromDate.next().monday(); | |
} | |
var toDate = Date.today().addDays(10); | |
if (toDate.is().saturday() || toDate.is().sunday()) { | |
toDate = toDate.next().monday(); | |
} | |
document.getElementById('fromDate').innerHTML = fromDate.toString('dddd MMMM dS'); | |
document.getElementById('toDate').innerHTML = toDate.toString('dddd MMMM dS'); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment