• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

count the days between two modules excluding Sundays

Participant ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

var nDiffDays = "";
var dd = this.getField("data1").value;
var rd = this.getField("data2").value;
if(dd.length && rd.length)
{
var d1 = util.scand("dd/m/yy", dd);
var d2 = util.scand("dd/m/yy", rd);

 if(d1 && d2)
        nDiffDays = Math.floor((d2 - d1)/86400000) +1;
}
event.value = nDiffDays;

from this code I have to exclude Sunday, so as to have a count of the days without Sunday. Thanks

TOPICS
PDF , PDF forms

Views

85

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 16, 2024 Nov 16, 2024

Try this:

var nDiffDays = 0;
var dd = this.getField("data1").value;
var rd = this.getField("data2").value;

if (dd.length && rd.length) {
 var d1 = util.scand("dd/m/yy", dd);
 var d2 = util.scand("dd/m/yy", rd);

if (d1 && d2) {
 if (d1 > d2) {
  var temp = d1;
  d1 = d2;
  d2 = temp;}
 var currentDate = new Date(d1);
 while (currentDate <= d2) {
 if (currentDate.getDay() !== 0) {
  nDiffDays++;}
  currentDate.setDate(currentDate.getDate() + 1);}}}

event.value = nDiffDays;

Votes

Translate

Translate
Community Expert ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

Try this:

var nDiffDays = 0;
var dd = this.getField("data1").value;
var rd = this.getField("data2").value;

if (dd.length && rd.length) {
 var d1 = util.scand("dd/m/yy", dd);
 var d2 = util.scand("dd/m/yy", rd);

if (d1 && d2) {
 if (d1 > d2) {
  var temp = d1;
  d1 = d2;
  d2 = temp;}
 var currentDate = new Date(d1);
 while (currentDate <= d2) {
 if (currentDate.getDay() !== 0) {
  nDiffDays++;}
  currentDate.setDate(currentDate.getDate() + 1);}}}

event.value = nDiffDays;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

LATEST

Thanks @Nesa Nurani 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines