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
Bob SandersBob Sanders 

How to convert NOW function into pst timezone in a text field?

Hello,
So I'm trying to convert the NOW function into pst time zone with the date format of "mm-dd-yyyy 00:00.00 AM/PM" in a text field. I have a workflow that updates a text field with text and time stamps it. I'm just trying to change the date format of NOW, I just don't know hwo to go about it outside of an Apex Class.

This is the current formula:
'Update text'+" "+ text(Now())

Any ideas?
 
Best Answer chosen by Bob Sanders
SathishPanjalaSathishPanjala

Salesforce gives the time in GMT format and by adding 5 hours you'll get PST time.

The below formula should work for your requirement with few tweaks.

IF( 
OR( 
 VALUE( MID( TEXT( MYTIMEFIELD + (5/24)), 12, 2 ) ) = 0, 
 VALUE( MID( TEXT( MYTIMEFIELD + (5/24) ), 12, 2 ) ) = 12 
), 
  "12", 
 TEXT( VALUE( MID( TEXT( MYTIMEFIELD + (5/24) ), 12, 2 ) ) 
 - 
IF( 
VALUE( MID( TEXT( MYTIMEFIELD + (5/24)), 12, 2 ) ) < 12, 
  0, 
  12 
  ) 
 ) 

& ":" & 
MID( TEXT( MYTIMEFIELD + (5 /24)), 15, 2 ) 
& ":" & 
MID( TEXT( MYTIMEFIELD + (5/24) ), 18, 2 ) 
& " " & 
IF( 
 VALUE( MID( TEXT( MYTIMEFIELD + (5/24)), 12, 2 ) ) < 12, 
 "AM", 
 "PM" 
)

Replace : MYTIMEFIELD with your Date & Time field.

If it answer your question, mark as solved.
 

Sathish P

All Answers

Raj VakatiRaj Vakati
'Update text'+" "+ text(Now().format('YYYY-MM-DD'))



Refer this link 



 
SathishPanjalaSathishPanjala

Salesforce gives the time in GMT format and by adding 5 hours you'll get PST time.

The below formula should work for your requirement with few tweaks.

IF( 
OR( 
 VALUE( MID( TEXT( MYTIMEFIELD + (5/24)), 12, 2 ) ) = 0, 
 VALUE( MID( TEXT( MYTIMEFIELD + (5/24) ), 12, 2 ) ) = 12 
), 
  "12", 
 TEXT( VALUE( MID( TEXT( MYTIMEFIELD + (5/24) ), 12, 2 ) ) 
 - 
IF( 
VALUE( MID( TEXT( MYTIMEFIELD + (5/24)), 12, 2 ) ) < 12, 
  0, 
  12 
  ) 
 ) 

& ":" & 
MID( TEXT( MYTIMEFIELD + (5 /24)), 15, 2 ) 
& ":" & 
MID( TEXT( MYTIMEFIELD + (5/24) ), 18, 2 ) 
& " " & 
IF( 
 VALUE( MID( TEXT( MYTIMEFIELD + (5/24)), 12, 2 ) ) < 12, 
 "AM", 
 "PM" 
)

Replace : MYTIMEFIELD with your Date & Time field.

If it answer your question, mark as solved.
 

Sathish P

This was selected as the best answer