Using dates in formulas
For the date return type, formulas can use the JavaScript Date
class. Formulas also can optionally return the number of milliseconds between midnight of January
1, 1970 and the specified date. Typically, you will create an instance of JavaScript
Date class and call getTime() on it. The following formula
returns the current date shifted forward by 24 hours (calculated using the current user's time
zone):
var d = new Date(rbv_api.getCurrentDate()); return d.getTime() + 24*60*60*1000;
new
Date() since it will return date in server's time zone which may be very confusing.
Date("{!date_field}") will create a Date object
corresponding to your date field. Example of date usage in formulas
You can use the standard JavaScript Date object in formulas.
The following formula shows how to calculate the difference in days between a PlatformDate field value and the current date, taking into account the user's
time zone setting:
var dt = new
Date("{!date_field}");
var today = new Date(rbv_api.getCurrentDate());
var day = 24*60*60*1000;
// Length of 24 hours on milliseconds
var days1 = Math.floor(dt.getTime()/day);
// Rounded down
var days2 = Math.floor(today.getTime()/day);
return days1 - days2;
getCurrentDate() API.