0

I need to add minutes in my time field in lightning component. When I simply try to add it, it's just concatenating them because time is in string type.

Is there an easy way to add minutes in the time field?

let programDataVar = component.get("v.ObjectName");
let fromTime = programDataVar.Start_Time__c;
let endtime = programDataVar.End_Time__c;

console.log(">>> Added time... "+fromTime + 30);

If my start time is 00:30:00.000 on adding 30 minutes it's becoming 00:30:00.00030

I know I can truncate each time attribute and then add minutes to it. But I want to make it dynamic, without truncating any value and adding any minute or hour.

0

The unit for adding or subtracting time values in milliseconds. For example, Timefield1__c has the value "2:00pm":

Timefield1__c + 600000 is “2:10pm” so 1min=60,000 milliseconds ,therefore for 30 min=30*60,000=1800000ms

Hope it helps!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.