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
Sandeep PatwardhanSandeep Patwardhan 

Adding day to date/time field and set time to specific time

Hello,

I am looking for modifying date/time field on record save to set date to next day and set time to 8.00am
e.g. if the date is 6/17/2016 12.20pm then on record save I want to save date to 6/18/2016 08:00am
Best Answer chosen by Sandeep Patwardhan
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Use this
DATETIMEVALUE(DATE(YEAR(DATEVALUE(Date_Time__c)), MONTH(DATEVALUE(Date_Time__c)), DAY(DATEVALUE(Date_Time__c)))) +1 + 14/24

All Answers

SalesFORCE_enFORCErSalesFORCE_enFORCEr
Use this
DATETIMEVALUE(DATE(YEAR(DATEVALUE(Date_Time__c)), MONTH(DATEVALUE(Date_Time__c)), DAY(DATEVALUE(Date_Time__c)))) +1 + 14/24
This was selected as the best answer
Sandeep PatwardhanSandeep Patwardhan
Will this work for any date time? It is not specific to 12.20pm. IT can be anything else.
But no matter what date is, I want to set it to 8am next day
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Yes it will work for any date time. It will add 1 day and reset the time to 8 AM.
Sandeep PatwardhanSandeep Patwardhan
Thanks. That worked. Can you please explain 14/24 part of it ? I got rest of the logic.
SalesFORCE_enFORCErSalesFORCE_enFORCEr
The formula before "14/24" gives you the next day in GMT i.e. 6PM and the formula to add hours to a date/time field in +N/24 where N is the number of hours. So, you want 8AM that means 6PM+14 Hours so 14/24.
Jeremy Anderson 28Jeremy Anderson 28
I am also looking for a similar formula that will set the datetime value for a field to 10 days after the date in another field. And the time in the datetime field must be set to 5pm. What would I use?
Jeremy Anderson 28Jeremy Anderson 28
The following seemed to work for me
 
datetimevalue(Offer_Date__c) + 10 + 21/24

 
Fareed Shuja 15Fareed Shuja 15
Hi. I have similar requirement. E.g. If the record created date is in working hours (Mon - Fri 8.30am to 5pm) then don't update the fieled. But if the the record is created outside the working hours, then set the date/time field value to the next working day 8.30am? Can you help please.