Insert Date in Macro | The place for Zendesk users to come together and share
Skip to main content
September 20, 2016
Question

Insert Date in Macro

  • September 20, 2016
  • 24 replies
  • 75 views

We have a Macro with a comment and we would like to include today's date in the Macro. Is there a placeholder for today's date that we can use?

For example, the Comment reads:

We have referred this to our tech support team on {today's date} and they typically respond to clients in 1-2 hours.

This topic has been closed for replies.

24 replies

September 20, 2016

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.)

Simon31Author
September 20, 2016

@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!

September 20, 2016

No problem Simon - I love to help!

Employee
September 21, 2016

Carsten is killing it, per usual. :)

May 11, 2017

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

Joel11
May 19, 2017

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'}}

 

Sebastian13
May 28, 2018

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?

Employee
June 5, 2018

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,

Sebastian13
June 6, 2018

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

Sebastian13
June 6, 2018

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