Calculating date Difference into int field
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Rupert,
Please, note that you have a typo in ccalculateTimeDifference, as you can see in this error: The code is specifically written for the date format that you have, so, once you make sure there are no syntax issues, it should work. Let me know if it does or if you get any other error
Please, note that you have a typo in ccalculateTimeDifference, as you can see in this error: The code is specifically written for the date format that you have, so, once you make sure there are no syntax issues, it should work. Let me know if it does or if you get any other error
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Rupert,
You are very welcome and I am glad that it finally works Sounds simple enough, but working with dates can always be a pain
You are very welcome and I am glad that it finally works Sounds simple enough, but working with dates can always be a pain
Cheers
Hi guys,
I am using this to validate the dates before saving and when i put one date in both fields the alert comes out as planned but if i put expiry date earlier then effective date it lets me save (which is wrong).... what am i missing here:
I am using this to validate the dates before saving and when i put one date in both fields the alert comes out as planned but if i put expiry date earlier then effective date it lets me save (which is wrong).... what am i missing here:
Code: Select all
fd.onsubmit(function() {
var calcStartTime = new Date(fd.field('EffectiveDate').value());
var calcEndTime = new Date(fd.field('ExpiryDate').value());
var timeDiff = Math.abs(calcEndTime.getTime() - calcStartTime.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if (diffDays < 1) {
alert('Expiry Date must be greater than Effective Date.');
return false;
}
return true;
});
Dear Katy,
Please refer to this topic from another community forum: https://community.plumsail.com/t/differ ... ipt/6860/2
The premade solution exists that calculates the difference between two dates correctly.
Please refer to this topic from another community forum: https://community.plumsail.com/t/differ ... ipt/6860/2
The premade solution exists that calculates the difference between two dates correctly.
Thanks Alex,
I will look at this now.... on the side note: the other forum on that community page you are referencing - is it where you want to move all the form discussions? I thought that one is for another product, not for the Form Designer....
I will look at this now.... on the side note: the other forum on that community page you are referencing - is it where you want to move all the form discussions? I thought that one is for another product, not for the Form Designer....
OK, i fixed that this code is working perfectly fine :
Just leaving it here if someone (or me later ) would need it....
Code: Select all
fd.onsubmit(function() {
var d1 = Date.parse(fd.field('ExpiryDate').value());
var d2 = Date.parse(fd.field('EffectiveDate').value());
if (d1 !=0) {
if (d1 <= d2) {
alert ('WRONG dates');
return false;
} else {
alert('RIGHT dates');
return true;
}
}
});
-
- Information
-
Who is online
Users browsing this forum: No registered users and 9 guests