<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Helpful Hints: Comparing Dates In Freemarker</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=119759998" />
  <subtitle>Helpful Hints: Comparing Dates In Freemarker</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=119759998</id>
  <updated>2026-04-03T18:17:11Z</updated>
  <dc:date>2026-04-03T18:17:11Z</dc:date>
  <entry>
    <title>RE: Helpful Hints: Comparing Dates In Freemarker</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119762723" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119762723</id>
    <updated>2020-08-15T08:27:09Z</updated>
    <published>2020-08-15T08:27:09Z</published>
    <summary type="html">You need to check for the field and also check the return of the getData method.&lt;br /&gt;&amp;lt;#if newField?? &amp;amp;&amp;amp; newField.getData()??&amp;gt; ...&lt;br /&gt;That should work for new fields. We add fields all the time.&lt;br /&gt;It is not really a bug, it is more like how this thing works. It reads the content and what&amp;#39;s in there, gets added. It doesn&amp;#39;t look at the structure and checks what fields could be available. That&amp;#39;s why it works after saving the content, the empty field is then added to the content.&lt;br /&gt;I have opened two feature requests a while ago regarding article fields:&lt;br /&gt;&lt;a href="https://issues.liferay.com/browse/LPS-114690?jql=creator%20in%20"&gt;https://issues.liferay.com/browse/LPS-114690&lt;/a&gt;&lt;br /&gt;&lt;a href="https://issues.liferay.com/browse/LPS-114686"&gt;https://issues.liferay.com/browse/LPS-114686&lt;/a&gt;</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2020-08-15T08:27:09Z</dc:date>
  </entry>
  <entry>
    <title>Helpful Hints: Comparing Dates In Freemarker</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119759997" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119759997</id>
    <updated>2020-08-13T21:40:00Z</updated>
    <published>2020-08-13T21:40:00Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Heads up on comparing dates in Freemarker for web content. I've found a bug whereby sometimes if you have a web content structure and template situation and you have hundreds of already published articles with that structure ... if you add a new structure and try to diplsay it all the exosting web content breaks.&lt;br&gt;&lt;br&gt;&lt;br&gt;Compare dates using ?long&lt;br&gt;&lt;br&gt;    &lt;pre&gt;&lt;code&gt;[code]&amp;lt;!-- Template updated 8/13/2020 or 1597352716000 --&amp;gt;
&amp;amp;lt;#assign changed = 1597352716000&amp;amp;gt;
&amp;amp;lt;#assign date = .vars['reserved-article-modified-date'].data&amp;amp;gt;
&amp;amp;lt;#assign date = date?datetime("EEE, d MMM yyyy HH:mm:ss Z")&amp;amp;gt;
&amp;amp;lt;#assign date = date?long&amp;amp;gt;

&amp;amp;lt;#assign now = .now?long&amp;amp;gt;

&amp;lt;p&amp;gt;1: ${date}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;2: ${changed}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;3: ${now}&amp;lt;/p&amp;gt;
    

&amp;amp;lt;#if date lt changed&amp;amp;gt;
    &amp;amp;lt;#assign cstatus = "stale"&amp;amp;gt;
&amp;amp;lt;#elseif date gt changed&amp;amp;gt;
    &amp;amp;lt;#assign cstatus = "fresh"&amp;amp;gt;
&amp;amp;lt;#else&amp;amp;gt;
    &amp;amp;lt;#assign cstatus = "unknown"&amp;amp;gt;
&amp;lt;!--#if--&amp;gt;

&amp;lt;p&amp;gt;Content Freshness: ${cstatus}&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span style="font-size: 18px;"&gt;It is possible to use ?? in Freemarker but for some reason this doesn't always &lt;/span&gt;suppress&lt;span style="font-size: 18px;"&gt;&amp;nbsp;the "missing &lt;/span&gt;reference errors&lt;span style="font-size: 18px;"&gt;". The template is refrencing a content field that isn't in the old &lt;/span&gt;versions&lt;span style="font-size: 18px;"&gt;&amp;nbsp;of the structures. The error goes away when the user republishes the content but this isn't acceotable to re-publish hundreds of articles.&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;I had to insert a hard epoch date as a cut off to judge if the content was updated after the change, if so it will find the missing data, if not it can't find the missing data ... so only look for the data if the content is freshly published.&lt;br&gt;&lt;br&gt;This may be useful to someone.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-08-13T21:40:00Z</dc:date>
  </entry>
</feed>
