Convert comment.created_at to EST timezone in trigger email

9 Comments

  • Devan
    Comment actions Permalink

    Hello Andrew,

    I would give the following formula a try and let me know if this works better for you?

    {{"now" | date: "%s" | minus : 18000 | date: "%Y-%m-%d %H:%M %P EST"}}

    Best regards. 

    0
  • Andrew Orner
    Comment actions Permalink

    Hi Devan, Unfortunately, that does not work, as I'm trying to use this formula to create a threaded email trigger (ie. as close as possible to a normal email). To your point, "now" would work for the most recent comment, but I also need to format timestamps for the previous comment, and the 2nd previous comment, and the 3rd previous comment, etc. 

    Any ideas? 

    0
  • Brett - Community Manager
    Comment actions Permalink

    Hey Andrew,

    Can you provide some additional context on how the formula provided isn't working? We're rather limited on what we can assist with on our end but perhaps some additional information can help other users jump in here.

    Thanks!

    0
  • Andrew Orner
    Comment actions Permalink

    Sure thing Brett- 

    As mentioned, I want end users to communicate with our support team using email (not Zendesk interface), so I want to get the trigger emails to look as close to an email thread as possible. 

    There are three conditions to my trigger: 

    1. Ticket Is Updated
    2. Comment Is Present, and requester can see the comment
    3. Comment Is Public

    Here's the email body code:

    {% capture commentcountminusone %}
    {{ticket.comments.size | minus: 1}}
    {% endcapture %}
    {% capture commentcountminustwo %}
    {{ticket.comments.size | minus: 2}}
    {% endcapture %}
    {% for comment in ticket.comments limit: 1%}
    <p>{{comment.value}}</p>
    {% for attachment in comment.attachments %}
    <p>Attachment:
    {{attachment.url}}</p>
    {% endfor %}
    {% endfor %}
    __________________
    {% for comment in ticket.comments offset:1 limit:commentcountminustwo%}
    <b>From: </b>{{comment.author.name}}{% for cc in ticket.ccs %}<br><b>Cc: </b>{{cc.email}}{% endfor %}
    <b>Sent: </b>{{comment.created_at_with_time | date: "%Y-%m-%d" }}
    <b> Subject: </b> RE: {{ticket.title}}
    <p>{{comment.value}}</p>
    {% for attachment in comment.attachments %}
    <p>Attachment:
    {{attachment.url}}</p>
    {% endfor %}
    __________________
    {% endfor %}

    {% for comment in ticket.comments offset: commentcountminusone%}
    <b>From: </b>{{comment.author.name}}{% for cc in ticket.ccs %}<br><b>Cc: </b>{{cc.email}}{% endfor %}
    <b>Sent: </b>{{comment.created_at_with_time | date: "%Y-%m-%d" }}
    <b> Subject: </b>{{ticket.title}}
    <p>{{comment.value}}</p>
    {% for attachment in comment.attachments %}
    <p>Attachment:
    {{attachment.url}}</p>
    {% endfor %}
    {% endfor %}


    Here's an example email thread that an end user could receive today: 

     

    Here's how I would like that same email thread to generate (notice the timestamp in the 'Sent' line): 

    0
  • Brett - Community Manager
    Comment actions Permalink

    Thanks for the additional information Andrew!

    While this isn't something I'm able to assist with on my end, I've contacted some of our amazing Community Moderators to see if they can offer up some guidance.

    The information you provided should help others jump in if they're able to do so :)

    Cheers!

    0
  • Karen D Snyder
    Comment actions Permalink

    Hi Andrew,

    I created a trigger with your code, and in both places where the date is inserted, changed {{comment.created_at_with_time | date: "%Y-%m-%d" }} to {{comment.created_at_with_time | date: "%s" | minus 18000 | date:"%Y-%m-%d %H:%M %P EST" }}, to test what was happening. I observed in the email sent from the trigger that 4:28pm PST (my time zone) was displayed in the email as 11:28 am EST, which is incorrect; it should be 7:28pm. That made me realize that comment.created_at_with_time was actually in my local time zone and did not need to be converted.

    When I changed the code to {{comment.created_at_with_time | date: "%s" | date: "%Y-%m-%d %I:%M %P PST" }}, the email displayed the correct time in my time zone. Note that I changed %H to %I, because %H uses 24-hour notation, and %I uses 12-hour notation.

    I got information on time formatting from http://strftime.net/, which was provided in another useful post on time formatting: https://support.zendesk.com/hc/en-us/community/posts/219699267-Insert-Date-in-Macro

    0
  • Brett - Community Manager
    Comment actions Permalink

    This is awesome! Thanks for sharing the solution Karen :)

    0
  • Karen D Snyder
    Comment actions Permalink

    Actually, I realized that the code that I provided above can be shortened, to:
    {{comment.created_at_with_time | date: "%Y-%m-%d %I:%M %P PST" }}

    I tested and verified that it works.

    0
  • Andrew Orner
    Comment actions Permalink

    Excellent! Works great. For those curious, here's the full code I pasted into the trigger's 'Email body' (first make sure that your time zone is correct: Admin > Settings > Account > Localization). 

    {% capture commentcountminusone %}
    {{ticket.comments.size | minus: 1}}
    {% endcapture %}
    {% capture commentcountminustwo %}
    {{ticket.comments.size | minus: 2}}
    {% endcapture %}
    {% for comment in ticket.comments limit: 1%}
    <p>{{comment.value}}</p>
    {% for attachment in comment.attachments %}
    <p>Attachment:
    {{attachment.url}}</p>
    {% endfor %}
    {% endfor %}
    __________________
    {% for comment in ticket.comments offset:1 limit:commentcountminustwo%}
    <b>From: </b>{{comment.author.name}}{% for cc in ticket.ccs %}<br><b>Cc: </b>{{cc.email}}{% endfor %}
    <b>Sent: </b>{{comment.created_at_with_time | date: "%s" | date: "%Y-%m-%d %I:%M %P EST" }}
    <b> Subject: </b> RE: {{ticket.title}}
    <p>{{comment.value}}</p>
    {% for attachment in comment.attachments %}
    <p>Attachment:
    {{attachment.url}}</p>
    {% endfor %}
    __________________
    {% endfor %}

    {% for comment in ticket.comments offset: commentcountminusone%}
    <b>From: </b>{{comment.author.name}}{% for cc in ticket.ccs %}<br><b>Cc: </b>{{cc.email}}{% endfor %}
    <b>Sent: </b>{{comment.created_at_with_time | date: "%s" | date: "%Y-%m-%d %I:%M %P EST" }}
    <b> Subject: </b>{{ticket.title}}
    <p>{{comment.value}}</p>
    {% for attachment in comment.attachments %}
    <p>Attachment:
    {{attachment.url}}</p>
    {% endfor %}
    {% endfor %}
    0

Please sign in to leave a comment.

Powered by Zendesk