Recent searches


No recent searches

Insert Date in Macro

Answered


Posted Sep 20, 2016

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.


3

24

24 comments

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

2


@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


No problem Simon - I love to help!

0


image avatar

Jessie Schutz

Zendesk Customer Care

Carsten is killing it, per usual. :)

0


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

0


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

 

0


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


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


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


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

0


image avatar

Dennis Lynn

Zendesk Customer Care

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


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


image avatar

ZZ Graeme Carmichael

Community Moderator

Tiffany

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

That same logic should work for you.

0


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


image avatar

ZZ Graeme Carmichael

Community Moderator

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


Graeme - THANKS!

0


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

0


image avatar

Brett Bowser

Zendesk Community Manager

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


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


image avatar

Brett Bowser

Zendesk Community Manager

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

0


Is it possible to generate a date for "Next Sunday"

We deploy patches on Sunday and I would like to have a macro that inserted this day.  

So if I ran it today (June 5) it would inset June 7

0


@...

there may be a simpler way to do it but this should work

finds day of week, minuses day of the week from 7. takes that calculates the seconds and then adds that to the current date.

test it out

{% assign today = 'now' | date: '%u' %}{% assign dayWeek = 7 | minus: today %}
{% assign seconds = dayWeek | times: 24 | times: 60 | times: 60 %}
{{ 'now' | date: '%s' | plus: seconds | date: '%Y-%m-%d' }}

0


Is there a code to generate a date 3 days from today not taking into consideration weekends? Thanks

0


@...

You want it to count three days in the future but not the weekends? If so, try out the below

Assigns today -> the day of the week

If wed -> then add 5 days in seconds to now == mon

if thurs -> then add 4 days in seconds to now == mon

else -> add 3 days in seconds to now

{% assign today = 'now' | date: '%A' %}
{% if  today == 'Wednesday' %}
{{ 'now' | date: '%s' | plus:432000 | date: '%Y-%m-%d' }}
{% elsif today == 'Thursday' %}
{{ 'now' | date: '%s' | plus:345600 | date: '%Y-%m-%d' }}

{% else %}
{{ 'now' | date: '%s' | plus:259200 | date: '%Y-%m-%d' }}
{% endif %}

0


Post is closed for comments.

Didn't find what you're looking for?

New post