Solved

Next Business Date using Javascript

Posted on 2016-10-24
2
41 Views
Last Modified: 2016-10-25
Can someone tell me how this can be achieved and what is the syntax?
0
Comment
Question by:teknovation
2 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 41857340
found this example online (twekaed to use todays date and the NEXT business day):

var startDate = "21-OCT-2016";
startDate = new Date(startDate.replace(/-/g, "/"));
var endDate = "", noOfDaysToAdd = 1, count = 0;
while(count < noOfDaysToAdd){
    endDate = new Date(startDate.setDate(startDate.getDate() + 1));
    if(endDate.getDay() != 0 && endDate.getDay() != 6){
       count++;
    }
}
alert(endDate);//You can format this date as per your requirement

Open in new window

0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41857563
<script>
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
// TEST FOR FRIDAY
var date = '2016-10-28';
var nbd = nextBusinessDay(date);
console.log("NBD for : " + date + " is [" + nbd + "] => " + days[nbd]);

//TEST FOR MONDAY
date = '2016-10-24';
nbd = nextBusinessDay(date)
console.log("NBD for : " + date + " is [" + nbd + "] => " + days[nbd]);

function nextBusinessDay(dt)
{
  var day = new Date (dt).getDay() + 1;
  day = (day > 5) ? 1 : day;
  return day;
}
</script>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now