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
Tyler TurnerTyler Turner 

How to extract hour from datetime field

Hello,

I'm trying to get the hour of day in EST from the Date/Time Opened field. I found two other posts around this and neither formula worked from those so I'm looking for help. Just need a simple number output for the hour of the day.

Thanks!
VinayVinay (Salesforce Developers) 
Hi Tyler,

Try below formula.
IF(
ISBLANK(Date_Time__c ),"0",
TEXT(MOD(VALUE(
Left(
right( trim(TEXT(Date_Time__c) ),9),2))+10,24))
&":"&mid(right( trim(TEXT(Date_Time__c) ),9),4,2)
)

https://developer.salesforce.com/forums/?id=9062I000000BngFQAS

Please mark as Best Answer if above information was helpful.

Thanks,
Karthik PadmakumarKarthik Padmakumar
Hi Tyler, 

For Apex you can use the fieldName.hours() to get the hour component. 
For formula field you can use - HOUR( TIMEVALUE(fieldName) )

Hope it helps you. 

Thanks, 
KP
APAP
Please check if this helps:
https://thesalesforcetutorial.blogspot.com/2021/07/how-to-calculate-number-of-hours.html
gfjhb rdtfggfjhb rdtfg
our pieces are handmade, the advantage here is that our artists and designers can custom-make pieces to suit the occasion.
CoCo works directly with the artists and designers to make that special gift for your corporate event Corporate gifts Australia (https://contemporaryco.com.au/collections/corporate-gifts).