Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Omit Weekend and Holidays in a Date Field

Avatar

Level 2

I have a date field where I'm showing a DUE DATE (today's date + 5) , but I want to be able to omit the weekends (for sure) and holidays (if possible).

The due date cannot be a weekend or a holiday. For example, if someone submits the form on a Monday, the DUE DATE would have to be the following Monday, not Friday, Saturday or Sunday. Is this possible? Here is the code I have that needs to be edited:

$.rawValue = (Num2Date(Date()+5, "EEEE MMMM D, YYYY"))

-Leonardo

5 Replies

Avatar

Former Community Member

This might be one of those cases where Javascript is nicer for Dates. There is a function in Javascript where you pass a date and you can get back the day of the week as a 0-6 value. Then you can test the returned value and if it is a 5 or 6 you can react accordingly. The function is Date.getDay().

As far as holidays are concerned you will have to check those one by one for your area.

Paul

Avatar

Level 2

Thaks Paul, but I know nothing about Javascript (or FormCalc for that matter). I did find some code that is simlar to what you described, but I don't know how to manipulate it to work in LiveCycle designer. Can this work in a DateField?

-Leonardo

-----------------------------------------------

<script type="text/javascript">
window.onload=function(){
nowAndThen();
}
function nowAndThen() {

days=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

now=new Date();
yy=now.getUTCFullYear();
mm=now.getUTCMonth();
dt=now.getUTCDate();
dd=now.getUTCDay();
now=now.toLocaleDateString();

switch(dd) {
case 0:dd=5;dt5=dt+8;
break;

case 1:dd=1;dt5=dt+7;
break;

case 2:dd=2;dt5=dt+7;
break;

case 3:dd=3;dt5=dt+9;
break;

case 4:dd=4;dt5=dt+7;
break;

case 5:dd=5;dt5=dt+7;
break;

case 6:dd=5;dt5=dt+6;
break;
}
forwardfive=new Date(yy,mm,dt5).toLocaleDateString();


document.getElementById('today').firstChild.nodeValue='Today is '+now;
document.getElementById('ahead5').firstChild.nodeValue='Five business days ahead it will be '+forwardfive;
}
</script>

Avatar

Former Community Member

Yes that is the gist of it ....I took the code and put it into a sample for you (see attached). I took it out of a function and made it run on it's own. The code is on the click event of the button. That will take care of weekends but not holidays.

Paul

Avatar

Level 2

Paul ~ Nice! We are getting there, but I'm sorry for not being clear.

I want the CURRENT DATE in your document to be the five days ahead instead of today's date; minus the weekend days. I don't need the text created by the button or need a button. I only need the code that will show the default date, five days ahead. Additionally, the user can change the date if they wanted to by choosing a different date using the date widget.

I hope that's clear.

-Leonardo

Avatar

Former Community Member

I did it that way to show you how it was done ....The field on that form is a date field so you can pick whatever date you want and the button just puts the code in nice spot for you to paruse! You can take the result from that script and instead of populating a message box you can assign the value to a field.

Paul