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
Salesforce GeekSalesforce Geek 

Subtract one minute from Current time

Hi There,

I’m newbie to Salesforce.

I would like to know the syntax “How to subtract one minute and two minutes from the current time”? I have checked in Datemethods in Apex documentation. No luck found.

Can anyone help?

Thanks
 
Best Answer chosen by Salesforce Geek
PratikPratik (Salesforce Developers) 
Hi,

This will work:

For 1 minute:   NOW() - (1/1440)
For 2 minutes:  NOW() - (2/1440)

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.

All Answers

PratikPratik (Salesforce Developers) 
Hi,

This will work:

For 1 minute:   NOW() - (1/1440)
For 2 minutes:  NOW() - (2/1440)

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
This was selected as the best answer
RishavRishav
Hii Geek,
   you can try like this for subtracting from minute 
   
DateTime myDateTime = DateTime.newInstance(2001, 2, 27, 3, 3, 3);
 integer minute = myDateTime.minute()-2;
System.debug('time is'+minute);
or you can try like this if you want to perform the operation with current time 
DateTime Cdatetime = DateTime.now();  
system.debug('current date time is '+cdateTime);
Integer min = cdateTime.minute();
system.debug('current minute value is '+min);
Integer twominuteBefore = min-2;
system.debug('two minute befor minute was'+twominuteBefore);

If  your problem solved then please mark it as best answer

Thanks 
Rishav


           
Salesforce GeekSalesforce Geek
Awesome. Thank You Pratik and Rishav.
PratikPratik (Salesforce Developers) 
Glad it helped! Thanks, Pratik
VamsiVamsi
Thank you Pratik.

It helped me a lot ....!!!!
Achuth PuriAchuth Puri
System.now().addMinutes(-1); // to subtract 1 min
System.now().addMinutes(-2); // to subtract 2 min
narinder singh 37narinder singh 37
thanks for this Shalimar game
Haripriya S 11Haripriya S 11
Can someone help me on how to use the same formula in vlocity component (Omnistudio Dataraptor)? I want to add 2 mins to NOW()