How to grab dynamic date in SendGrid's Dynamic templates? - date

How do I get the current year for the Copyright © {{YEAR}} in a SendGrid Dynamic Templates WITHOUT test data?
I'm looking for something like {{ formateDate new Date YYYY }} since we want the year to update automatically so we can't rely on test data if that is possible?

Related

Can we get current date and calculate dates in a Jinja2 template?

Context:
There is a framework that processes Jinja2 templates and creates AWS resources based on the JSON file generated from the Jinja2 templates. One field value in these templates is a date.
Problem:
I want a template which automagically calculates the future date 5 days from the current date in the following format: MMDDYYYY, preferably without passing any parameter to this template file.
I have no means to alter the processing framework, so i can only work with what template i feed in.
Questions:
Can any of these done in a Jinja2 template file?
get current date
calculate date which is 5 days later than a provided date in
MMDDYYYY format

Mailchimp conditional merge tags - to use conditional date logic based on today

I am using a date token, which is filled in a signup form. I would like to do conditional logic, based on whether the date is less than 2 weeks away from today. I would like to do something like the below
*|IF:CHECKINDATE<TODAY+20DAYS|*
This is the code for your accommodation: 123456789
*|END:IF|*
Do you know if it is possible?

Freemarker Date Field to display last business day of the month

I am VERY new to Freemarker. Apparently, it is the template model of choice in NetSuite. I am tasked with updating an email template to display a line of text that includes the last business day of the month.
I see how to display the field in documentation that I have found and here is my code for that.
<#assign aDateTime = .now>
<#assign aDate = aDateTime?date>
<span>PLEASE EXPEDITE ORDER PROCESSING AND SHIP OVERNIGHT TO GUARANTEE DELIVERY BY EOD
THE LAST BUSINESS DAY OF THE MONTH ${aDate}</span>
My question, since I clueless here, is how to display the last business day of the month?
EDITED TO ADD: I have found that the add ins for Freemarker date manipulation can be of some assistance here (based on another thread here). The issue is getting the right logic down to show the date. Here is an example of subtracting 18 days from a certain date:
${(mydate?long - 18 * 86400000)?number_to_date?string("yyyy-MM-dd")}
So I know there is a way to do what I am trying to do with this, but I just can't wrap my head around it.
Any and all assistance would be greatly appreciated.
Thanks.
There are a couple of approaches here depending on how the template is being called. If you are using this as a standard template triggered on a record (transaction) then you need to get the last business day of the month value into a custom field on the record. You could do that by creating a custom record of months that has a start and end date and a last business day. Then you make your last business day field a
Custom Body Date Field
Non-Stored
Defaulted from a saved search
The saved search uses either today's date or some date from the transaction to lookup the date's month's last business day. Of course if that is based on the transaction's date then you can set the value with a script.
If you can set it with a script the custom record solution still works. What I've done in the past though is build a function that can do business date calculations based on the account's location (US or Australia) and the observed statutory holidays.
Both approaches require occasional updates. The function of course could also be used to generate upcoming last business dates.
A couple of examples of business day calculations are in my github repo for Netsuite things. calculateShippingDates and calcNSWBusinessDays are examples of generating calculating spans of business days. calculateShippingDates actually has a last business day of month calc.
HTH
I figured this out. I used a thread showing how javascript picked the last day of the month (link here) and then converted that code to Freemarker. Here is the Freemarker code snippet:
<#assign aMonth = .now?string("M")>
<#assign aNewMonth = aMonth?number>
<#assign aYear = .now?string("yyyy")>
<#assign aDay = 0>
<#assign aNewDate = "" + (aNewMonth + 1) + "/" + aDay + "/" + aYear>
<#assign aLastDay = aNewDate?date>
MONTH: ${aNewMonth}<br />
YEAR: ${aYear}<br />
${aLastDay?string.full}<br />
This is the LAST day of the month. I do some if then else logic to determine if the string is a Saturday or Sunday and then print out the correct last business day of the month.

Date related operations in jinja2

I am using cratejoy to create a 'subscription boxes' based website.It used jinja2 as its templating engine.
Now I am editing email templates where I want to access order items and send my customized messages.
My question is how to do date related operations using jinja2 syntax just as getting-
date on next monday,
next month name,
first monday of next month etc
I am able to do everything easiliy with javascript but it wont be helpful since email clients wont run JS.
Any help will be appreciated !!

How to render only the Year when using date picker from OctoberCMS backend?

I’m using the date picker from the backend, and I’d like to display only the year that the user has selected. For example, instead of rendering 23-12-2017 on the DOM when is use {{ record.year }}, I’d only like to render the year 2017. How do I do this ? Is there a filter or something ?
You can use the date filter for Twig:
{{ record.date|date("Y") }}
By the way, if you are only using the year part of the date, you should also only save the year to the database, not the whole date. This would also mean you wouldn't have to format it in the first place.
And if you need to save the whole date, please consider naming it something other than just year :)