Monday, July 25, 2016

convert a Date/Time field for any timezone

Salesforce saves the date/time fields on GMT Timezone. It is difficult to the users who works on different time zones. Here is solution

create a formula field that calculates the time based on the timzone. Please try the below example. The example which i showed you will work for PST.  if needed to use that in IST change the values (-7 & -8) to 5.5

IF ( DATEVALUE(CreatedDate) >=
DATE ( YEAR (DATEVALUE(CreatedDate)),3,1)
+
(14-
CASE( MOD(DATE ( YEAR (DATEVALUE(CreatedDate)),3,1) - DATE (1900,1,7),7) ,
0,7,MOD(DATE ( YEAR (DATEVALUE(CreatedDate)),3,1) - DATE (1900,1,7),7))
)
&&
DATEVALUE(CreatedDate) <
DATE ( YEAR (DATEVALUE(CreatedDate)),11,1)
+
(7-
CASE( MOD(DATE ( YEAR (DATEVALUE(CreatedDate)),11,1) - DATE (1900,1,7),7) ,
0,7,MOD(DATE ( YEAR (DATEVALUE(CreatedDate)),11,1) - DATE (1900,1,7),7))
),
LEFT ( TEXT (CreatedDate- 7/24 ), 16),
LEFT ( TEXT (CreatedDate- 8/24), 16)
)


1 comment:

  1. Your post is really good providing good information.. I liked it and enjoyed reading it. Keep sharing such important posts.
    Salesforce Development

    ReplyDelete