I need to display date D+3 in javascript. Saturday and sunday i am unavailable.
Ex. : if it is Friday, October 25, date displayed should be Wednesday, October 30.
Thanks for your precious help.
I need to display date D+3 in javascript. Saturday and sunday i am unavailable.
Ex. : if it is Friday, October 25, date displayed should be Wednesday, October 30.
Thanks for your precious help.
var today = new Date(); // Or Date.today()
var d3 = today.add(3).day();
easy right
This also helps
var today = new Date();
if(today.getDay()==0||today.getDay()==1||today.getDay()==2)
{
//sun,mon,tue
today.setDate(today.getDate() + 3);
}
else if(today.getDay()==3||today.getDay()==4||today.getDay()==5)
{
//wed,thu,fri
today.setDate(today.getDate() + 5);
}
else
{
//sat
today.setDate(today.getDate() + 4);
}
and next the formatting of your choice
var dd = today.getDate();
var mm = today.getMonth() + 1;
var y = today.getFullYear();
var formattedDate= dd + '/'+ mm + '/'+ y;
I have made this function for a project to calculate working days, it will work for you.
All you have to do is to
1. set a start date in your case current date.
2.working days slider(no of days you want(ex: 3))
and it will return end date Excluding Saturdays and Sundays.
function GetNextworkingDay() {
//get the value of Start Date here
var startDate = new Date(); // this gets the current date// can also provide any specific date here.
var endDate = new Date();
//Get the No of Days to perform a task.
var NoOfDaysForTask = 3;
//Initial End Date
endDate.setDate(startDate.getDate() + NoOfDaysForTask);
endDate.setHours(00, 00, 00);
var WorkingDaysCountInRange = parseInt(GetWorkingDaysCountInRange(startDate, endDate))
//Increase the range and calculate till we get the Specified no foworking days.
while (NoOfDaysForTask != WorkingDaysCountInRange) {
endDate.setDate(endDate.getDate() + parseInt(NoOfDaysForTask - WorkingDaysCountInRange));
WorkingDaysCountInRange = parseInt(GetWorkingDaysCountInRange(startDate, endDate))
}
alert(endDate);
});
//This function will check if we are getting the required no of workingdays in the range limit passed
//if not then range will be Increased and it will be calculated again
function GetWorkingDaysCountInRange(startDate, endDate) {
var taskStartDate = new Date(startDate);
var taskCompletionDate = new Date(endDate);
var weekDaysCount = 0
while (taskStartDate < taskCompletionDate) {
var day = taskStartDate.getDay();
var isWeekend = (day == 6) || (day == 0);
if (!isWeekend) {
weekDaysCount++;
}
taskStartDate.setDate(taskStartDate.getDate() + 1);
}
var day = taskCompletionDate.getDay();
var isWeekend = (day == 6) || (day == 0);
if (isWeekend) {
weekDaysCount--;
}
return weekDaysCount;
}