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
CharlieLangCharlieLang 

DATETIMEVALUE Adding Hours to the formula

I am trying to set the hour in a time date field but am unsure how to add the hours to the field - every time i try and add the 'start time' field salesforce is just adding days to the formula.

 

this is the formula as i have it at the moment : DATETIMEVALUE(CloseDate +(TimeOfAppointment__c) )

 

So what i am hoping for is that if the field with the time of the appointment, say 10, the formula would would show 10am on the closedate.

 

the reason behind this is that i am trying to create an event in visual workflow and i am unable to create a timedate field so was going to use this to create the start and end times for an event

Best Answer chosen by Admin (Salesforce Developers) 
Justine HeritageJustine Heritage

This would probably be easiest.

 

DATETIMEVALUE( TEXT( CloseDate ) & " " & TimeOfAppointment_c ) + ( X / 24 )

 

Where TimeOfAppointment_c is a text field formatted as HH:MM:SS (24 hour format) and X / 24 represents the time difference between your time zone and Greenwich Mean Time (GMT). For example, if your org is in San Francisco, X would be 7 because PDT is GMT-7. X could change based on daylight saving time, so this is something you'll have to be aware of. Times are tricky to deal with in Salesforce.

All Answers

Justine HeritageJustine Heritage

This would probably be easiest.

 

DATETIMEVALUE( TEXT( CloseDate ) & " " & TimeOfAppointment_c ) + ( X / 24 )

 

Where TimeOfAppointment_c is a text field formatted as HH:MM:SS (24 hour format) and X / 24 represents the time difference between your time zone and Greenwich Mean Time (GMT). For example, if your org is in San Francisco, X would be 7 because PDT is GMT-7. X could change based on daylight saving time, so this is something you'll have to be aware of. Times are tricky to deal with in Salesforce.

This was selected as the best answer
CharlieLangCharlieLang

Thanks for that it worked a treat. next issue is that i just realised visual workflow doesnt have date / time function. balls