Reputation: 25
I'm one of the naive developer of XPages application. I took up XPages as I find them really interesting to build whatever we want.
Here is one of my problems on which I am working from days but couldn't get over it.
In my Leave application, I have two date fields, leaveFrom & leaveTill and one computed edit box where I would display the no. of days (noDays) dynamically i.e. the difference of above two leave date fields. And I am unable to do such a simple thing.
I'm using Lotus 8.5.3 for creating this application. I saw some of the methods like getcomponent("").setvalue()
or getvalue()
. But these two methods are not available in 8.5.3. I always get error when I use these methods. I tried using getComponent on CSJS also.. but no success.
I also tried using other script methods, I could get backend documents created but value is not showing on my current xpage.
Please show me the correct path.
Upvotes: 0
Views: 1668
Reputation: 10485
The code is not working because the method timeDifference did not exists for Java dates:
var difference = endDate.timeDifference(startDate);
You have to convert it to NotesDateTime first:
var difference = null;
try{
var nDateStart = session.createDateTime( startDate );
var nDateEnd = session.createDateTime( endDate );
difference = nDateEnd.timeDifference(nDateStart);
difference = (Math.floor(difference/86400)) + 1;
}catch(e){return e}
difference
Upvotes: 2
Reputation: 9349
Thanks to your explanatory videos, I learned a lot from them.
Notes in 9? :)
Back to your question.
If both fields are DATETIME format then you can do something like the following.
(endDate - startDate) / (24*60*60);
Upvotes: 0
Reputation: 21709
You can use the following XSnippet to compare dates (and thereby also calculate number of days between two dates): http://openntf.org/XSnippets.nsf/snippet.xsp?id=compare-dates. I hope yuou can use this as input for your specific case.
With regards to getComponent("").getValue() and .setValue(). They are certainly available in 8.5.3 too. Remember that XPages is case sensitive.
Upvotes: 4