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
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;
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Thanks @Nesa Nurani