Insert Date in Macro

Avec réponse

20 Commentaires

  • Carsten Falborg
    Actions pour les commentaires Permalien

    Hi Simon

    This should work: 

    {% capture today %}{{'now' | date:'%Y-%m-%d'}}{% endcapture %}{{today}}

    The output is based on UTC though, so to adjust for another timezone, you'll have to add or subtract the difference in hours. Current Eastern Time would be:

    {% capture today %}{{'now' | date:'%s' | minus:14400 | date:'%Y-%m-%d'}}{% endcapture %}{{today}}

    (Copied this from Jason Littrell here.)

    1
  • SwapNights.com Support Team
    Actions pour les commentaires Permalien

    @carsten Thank you so much for taking the time to help me by passing on this great answer from Jason (I searched and did not find!). As it happens we use UTC, so that is all good, but really appreciated you would think to reach out and help in this way!

    0
  • Carsten Falborg
    Actions pour les commentaires Permalien

    No problem Simon - I love to help!

    0
  • Jessie Schutz
    Actions pour les commentaires Permalien

    Carsten is killing it, per usual. :)

    0
  • Thomas Jensen
    Actions pour les commentaires Permalien

    How do you get the time value added to that string? I want both current date and time to be captured.

    0
  • Joel Hellman
    Actions pour les commentaires Permalien

    If you want date and time, format the date along these lines, adjust the minus (or replace with plus) according to your current UTC offset:

    {{'now' | date:'%s' | minus: 7200 | date:'%Y-%m-%d %H %M'}}

    Here is a easy reference for the date&time formats: http://strftime.net/

    You don't need that capture markup here, unless you want to reference that variable elsewhere. 

    will generate this output:

    Tip: you can test your liquid markup in the comment editor as well, before moving it into a proper macro.

    If UTC timestamps works for you, you can shorten it like below (but mind the first syntax is required if you want to adjust for your timezone):

    {{'now' | date:'%Y-%m-%d %H:%M'}}

     

    1
  • sebastian
    Actions pour les commentaires Permalien

    Momentarily it's UTC+2 here at my place. Is there a way to get the summer- and wintertime automatically or does it need some more coding for that?

    0
  • Daniel Yousaf
    Actions pour les commentaires Permalien

    Hi Sebastian!

    To fully answer your question I'll need to get some info on your use-case/goal.  I've created a ticket where we can discuss this, and you'll receive an email from me shortly :)

    Cheers,

    0
  • sebastian
    Actions pour les commentaires Permalien

    Hello Daniel,

    A day changes at midnight. So having the date imported through the above function means one needs the exact time for it. UTC doesn't know summer or winter time. So I first have to adjust the time to the timezone but the summer-winter-time part remains. Is there a way to change this automatically? Otherwise I would have to live with a one hour inaccuracy or would have to change the amount of hours to add to UTC each half year.

    Is there a way to automate it?

    Best regards,
    Sebastian

    0
  • sebastian
    Actions pour les commentaires Permalien

    PS: Yes, it's daylight saving time related.

    0
  • Dennis Lynn
    Actions pour les commentaires Permalien

    Considering the suggestions that Carsten and Joel have provided here where you are manually calculating a UTC offset, I would suggest creating two version of the macro - one where the offset includes daylight savings time, and one where it doesn't. Then, your team would simply need to select the appropriate macro based on the time of year. It's not perfect because there is a chance that your agents might accidentally choose the wrong macro version, but the risk should be fairly small.

    I have no idea exactly how this could work, but the only alternative I can think of would be to create an app and upload it to Zendesk, and have the app systematically determine the right time based on the timezone you are in at the time you request the ticket update. Though an app could possibly lower the odds of the wrong time going out from accidental macro selection, there would be more up-front time/resources invested in the app creation and ongoing maintenance. 

    0
  • Tiffany Soucy
    Actions pour les commentaires Permalien

    Hello,

    I really like this insert date function.

     

    I have a question for you regarding adding a FUTURE date. We have a 30 day free trial of our software and I've used the string to achieve the start date (today's date) but how would I adjust the string to capture 30 days from today's date?

    0
  • Graeme Carmichael
    Actions pour les commentaires Permalien

    Tiffany

    I was able to generate a future date on this thread.

    That same logic should work for you.

    1
  • Jeff Callahan
    Actions pour les commentaires Permalien

    We have a custom date field on our Organization Object

    I can get this to populate with a macro using the field placeholder - {{ticket.organization.custom_fields.last_upgrade}}

    However the output format includes the Date and Time - e.g. 2018-12-09 00:00:00 +0000

    Is there a way to format this to just output the date?

    0
  • Graeme Carmichael
    Actions pour les commentaires Permalien

    Jeff

    You can control the format of the date like this:

    {{ticket.organization.custom_fields.last_upgrade | date: "%-d %B %Y" }}

    .. to give: 14 January 2019

    You can find the formatting codes here.

    0
  • Jeff Callahan
    Actions pour les commentaires Permalien

    Graeme - THANKS!

    0
  • Christian Herrmann
    Actions pour les commentaires Permalien

    Is it possible to echo the name of the current month in the user's language?

    0
  • Brett - Community Manager
    Actions pour les commentaires Permalien

    Hey Christian,

    It looks like natively this isn't possible with the existing placeholders which I've linked for you. That being said, it looks like you may be able to accomplish this using liquid markup in your triggers. I was able to track down the following Support Tip: Reference the current timestamp in a ticket update which goes over referencing the current time stamp as you update the ticket using liquid markup in your notification triggers.

    I've also attached our documentation for Using Liquid markup to support multiple languages in automations, macros, and triggers (Professional and Enterprise) that I hope you'll find useful as well.

    The above should hopefully get you close to what you're trying to accomplish.

    Cheers!

    0
  • Christian Herrmann
    Actions pour les commentaires Permalien

    I've done it thanks to your hints. It's a beast of a string but it works.

    excerpt for german:

    {% assign mon = 'now' | date: "%B" %}{% case mon %}{% when 'January' %}**Januar**{% when 'February' %}**Februar** [...] {% else %}Monat{% endcase %} bla

    It must be possible to use some more if/then/or to divide different user languages in only one dynamic content placeholder but I'm fine with it now. Thank you.

    0
  • Brett - Community Manager
    Actions pour les commentaires Permalien

    Thanks for sharing Christian and glad you were able to get this working :)

    0

Veuillez vous connecter pour laisser un commentaire.

Réalisé par Zendesk