My insights on Date And Datetime fields


I would like to share my recent experience with Date fields and timezone.

Scenario 1:

Created a date field 'CustomDate__c'. I configured a validation rule which says ,
CustomDate__c > Today()

Problem:

There are different users from different timezones, who can update the record. So, when two users from different timezones say PST(UTC-8), SGT(UTC+8) try to update this record, assuming that
Today is Feb 8 2016 according to SGT,

SGT User updates 'CustomDate__c' to Feb 8 2016. Validation rule won't fire this time.

Now, when PST user tries to update another field on the same record, this user encounters validation error as Today according to this user is Feb 7th 2016.


Scenario 2:

I had two date fields 'Submission Date' & 'Approved / Rejected Date' on an object. These fields get updated whenever record is submitted for approval & when record is approved/rejected using Field updates in Approval process.

Field Updates are configured using the below formula:
Today()

Problem:

When SGT user logs in and submits a record for approval, the Submission Date is populated as 8th Feb 2016. (Assuming today as 8th Feb). This is fine.


When PST user approves/rejects this record, the 'Approved/Rejected Date' is populated as 7th Feb 2016.(According to the users timezone, Today is 7th Feb 2016 for this user).

So Now, Submission Date is 8th Feb 2016 and Approved/Rejected Date is 7th Feb 2016.

When SGT user now try to edit record, he is encountering a validation error which I configured: Submission date cannot be greater than Approved/Rejected Date.


Solution for above scenarios:

Convert the date fields to date time fields. If you are having users from different timezones, it is always best to use Datetime fields.

You will not encounter the above scenarios if users are from same timezone.



Comments

  1. Hi Surendranadh,
    Even if we convert date fields to date time fields, it stores like 'YYYY-MM-DDThh:mm:ss.sssZ'. In your case submission date (2016-02-08T11:30:00:000Z) & approved date (2016-02-07T11:30:00:000Z). How this can solve the issue ? .If I am wrong please explain clearly..

    ReplyDelete
  2. Hi,

    Datetime fields will be stored in GMT time. But when user views the record in Detail page, Datetime fields will be displayed based on user timezone.

    If you are still unclear, try to replicate the scenarios in your devbox, you will get to know.

    ReplyDelete

Post a Comment

Popular posts from this blog

New Beta Architect Certifications by Salesforce

How to deploy Processes in Process builder using ANT?