function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rasbehari DasRasbehari Das 

How to do StartDate and EndDate validation in date time picker in standard form.

AbhishekAbhishek (Salesforce Developers) 
Hi Das,

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


OR

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 the 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"

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.