skipping sunday in working day in js
Hi friends
I like to share some code to validate the date in number of days along with skipping sunday to validate working day in week.
<span id="result"></span>
var day= 14;
document.getElementById('result').innerHTML = addDays(day);
function addDays(day){
var day = parseInt(day);
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
for(var i=0;i<=day;i++){
var dates = new Date();
dates.setDate(dates.getDate() + i);
//console.log(weekday[dates.getDay()]);
if(weekday[dates.getDay()]=='Sunday'){
console.log('first if');
console.log(day);
day = day+1;
}
}
day = parseInt(day);
var datess = new Date();
datess.setDate(datess.getDate() + day);
if(weekday[datess.getDay()]=='Sunday'){
console.log('second if');
day = day+1;
}
var date = new Date();
if(!isNaN(date.getTime())){
date.setDate(date.getDate() + day);
console.log(day);
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
if(isNaN(date.getDate())){
return '';
}
return 'Ships on '+ weekday[date.getDay()]+', '+date.getDate()+' '+monthNames[date.getMonth()];
}
return false;
}
I like to share some code to validate the date in number of days along with skipping sunday to validate working day in week.
<span id="result"></span>
var day= 14;
document.getElementById('result').innerHTML = addDays(day);
function addDays(day){
var day = parseInt(day);
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
for(var i=0;i<=day;i++){
var dates = new Date();
dates.setDate(dates.getDate() + i);
//console.log(weekday[dates.getDay()]);
if(weekday[dates.getDay()]=='Sunday'){
console.log('first if');
console.log(day);
day = day+1;
}
}
day = parseInt(day);
var datess = new Date();
datess.setDate(datess.getDate() + day);
if(weekday[datess.getDay()]=='Sunday'){
console.log('second if');
day = day+1;
}
var date = new Date();
if(!isNaN(date.getTime())){
date.setDate(date.getDate() + day);
console.log(day);
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
if(isNaN(date.getDate())){
return '';
}
return 'Ships on '+ weekday[date.getDay()]+', '+date.getDate()+' '+monthNames[date.getMonth()];
}
return false;
}
Comments
Post a Comment