Activity › Forums › Salesforce® Discussions › How to get start date and end date with time in single function from calendar in Salesforce?
Tagged: Calendar in Salesforce, Date Field, Date Value, Datetime, Datetime Field, datetimepicker, Salesforce Function
-
How to get start date and end date with time in single function from calendar in Salesforce?
Posted by Amresh Tiwari on March 28, 2018 at 12:37 PMIn calendar if user choose start date and end date how to calculate time of both and how the single function can handle both start date and end date.
Parul replied 7 years, 7 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Amresh,
We can achieve it by Salesforce standard functionality so please follow below steps to do so.
- Create Date field on any object name “Start Date”
- Create Date field on same object name “End Date”
- Create Formula field on same object name “Number of days”
- make sure the return type of formula field should be number.
- after creating record you can achieve what you want.
Thanks
- [adinserter block='9']
-
Hi Amresh,
Do you want to calculate the no. of days between the start date and end date of date time type? If yes, then from calendar you can get and start date and end date in variable
If the total duration is less than 24 hours, the following code works in javascript
var now = “04/09/2013 15:00:00”;
var then = “04/09/2013 14:20:30″;moment.utc(moment(now,”DD/MM/YYYY HH:mm:ss”).diff(moment(then,”DD/MM/YYYY HH:mm:ss”))).format(“HH:mm:ss”)
This approach will work ONLY when the total duration is less than 24 hours:var now = “04/09/2013 15:00:00”;
var then = “04/09/2013 14:20:30″;moment.utc(moment(now,”DD/MM/YYYY HH:mm:ss”).diff(moment(then,”DD/MM/YYYY HH:mm:ss”))).format(“HH:mm:ss”)
// outputs: “00:39:30”
If the response for durations of 24 hours or greater, then following code works in javascript
var now = “04/09/2013 15:00:00”;
var then = “02/09/2013 14:20:30″;var ms = moment(now,”DD/MM/YYYY HH:mm:ss”).diff(moment(then,”DD/MM/YYYY HH:mm:ss”));
var d = moment.duration(ms);
var s = Math.floor(d.asHours()) + moment.utc(ms).format(“:mm:ss”);// outputs: “48:39:30”
-
Hi,
Please follow the formula to get the achieve the functionality
DATE( Year([start date])+floor((MONTH([start date]) + [# of months] – 1) / 12) ,
mod(MONTH([start date]) + [# of months] -1, 12) + 1 ,
day([start date])
) – 1
Log In to reply.