Blog publish date for email without timestamp (HubL)

SOLVE
Amit_95
Member | Platinum Partner

I'm currently setting up blog notification emails and by default they display the datetimestamp when using {{ post.publish_date}}.

 

However, I want time removed and for it to only display the publish date (i.e. Jan 12, 2017).

 

I've tried to format the tag: {{ post.publish_date|datetimeformat('%B %e %Y') }} but nothing shows (not even the date). 

 

Using {{post.published|datetimeformat('%b %e, %Y')}} shows today's date (no timestamp).

 

Ideas on how I can achieve the above with no timestamp?

0 Upvotes
1 Accepted solution

Accepted Solutions
tjoyce
Solution
Recognized Expert | Platinum Partner

Gotcha, 

Thank you for the extended details on what you have tried and debugged.

Try adding this to your HUBL

{% set splitDate = post.publish_date|split(' ', 4) %}
{{splitDate[0]}} {{splitDate[1]}} {{splitDate[2]}}

 


tim@belch.io

View solution in original post

0 Upvotes
6 Replies 6
tjoyce
Recognized Expert | Platinum Partner

It sounds like your "post" object is empty. Are you sure the item in the loop is called "post"? It might be called "content" so, something like 

{{content.publish_date|datetimeformat('%B %e %Y') }}

Should work. Generally, the issues you are seeing are related to an empty publish_date (even when you get today's date showing up)


tim@belch.io
0 Upvotes
Amit_95
Member | Platinum Partner
{{content.publish_date|datetimeformat('%B %e %Y') }}

... works when placing it in blog listing pages.

 

But when I'm trying to create blog notification emails, using the same HubL, it displays today's date?

 

I have {{ post.author_line }} which pulls the author fine, but using the same logic {{post.publish_date|datetimeformat('%B %e %Y') }} doesn't work?

 

Code block being used:

 

<h2>{{ post.title }}</h2>
<p>{{ post.author_line }} - {{post.publish_date|datetimeformat('%B %e %Y') }}</p>
<p>{{ post.summary }}</p>

I have tried: 

 

<h2>{{ post.title }}</h2>
<p>{{ post.author_line }} - {{content.publish_date|datetimeformat('%B %e %Y') }}</p>
<p>{{ post.summary }}</p>
0 Upvotes
tjoyce
Solution
Recognized Expert | Platinum Partner

Gotcha, 

Thank you for the extended details on what you have tried and debugged.

Try adding this to your HUBL

{% set splitDate = post.publish_date|split(' ', 4) %}
{{splitDate[0]}} {{splitDate[1]}} {{splitDate[2]}}

 


tim@belch.io

View solution in original post

0 Upvotes
Amit_95
Member | Platinum Partner

Legend! Cheers, works perfectly!

RyanPatterson
Participant | Platinum Partner

Not sure if something changed since this was posted, but this solution no longer works. It will print the day of the week, the month and then day of the month but not the year. The output now looks like:

Wednesday, March 25,

So figured the year would be the 4 item in the array, but when i add splitDate[3] it adds year and time together. 

Any updated code that might help?

0 Upvotes
RyanPatterson
Participant | Platinum Partner

Figure it out, just have to change split(' ', 4) to split(' ', 5)

0 Upvotes