< Back

Document Subject: Create a Javascript Date from an Xpages date field and work out difference between dates
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#xpage_date or http://A555F9/nn.nsf/ByAlias/xpage_date

You can use @functions to grab things like @Day and @Month and @Year from a xpage date field. However you cannot do date1-date2 to get seconds and then days.




To create a javascript date from an XPages date field:

var Start_Date = getComponent("Start_Date").getValue();
var End_Date = getComponent("End_Date").getValue();

var st = new Date(@Year(Start_Date), @Month(Start_Date), @Day(Start_Date));
var et = new Date(@Year(End_Date), @Month(End_Date), @Day(End_Date));

//Set 1 day in milliseconds
var one_day=1000*60*60*24

//Work out number of days bewteen two dates
getComponent("DaysInRange").setValue(
@If(Start_Date.toString()=="" | End_Date.toString()=="" , 0 ,

1+Math.ceil( (et.getTime()-st.getTime())/(one_day)) )