Calculating date Difference into int field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

30 Nov 2018

Dear Rupert,
Please, note that you have a typo in ccalculateTimeDifference, as you can see in this error:
Typo.png
Typo.png (36.17 KiB) Viewed 1861 times
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 :roll:
Cheers

User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

30 Nov 2018

My Fault! Yes that works correctly.

Thank you very much for your help.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

30 Nov 2018

Dear Rupert,
You are very welcome and I am glad that it finally works :D Sounds simple enough, but working with dates can always be a pain :P
Cheers

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

25 Jan 2019

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:

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;
});

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

25 Jan 2019

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.

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

25 Jan 2019

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....

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

25 Jan 2019

Dear Katy,

No no, it's just one of the rare cases, when a solution is quite universal for both products :)

Feel free to ask, if you have troubles in implementation.

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

25 Jan 2019

fixed below
Last edited by Katy on 25 Jan 2019, edited 1 time in total.

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

25 Jan 2019

fixed below
Last edited by Katy on 25 Jan 2019, edited 2 times in total.

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

25 Jan 2019

OK, i fixed that :-) this code is working perfectly fine :-) :

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;
}
}
});
Just leaving it here if someone (or me later :-) ) would need it....

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests