Forum Discussion

clemensw's avatar
7 years ago

LiQL view_friendly_date of post_time

Dear Community,

we are using a LiQL query like that:

<#assign mostviewedMessages = restadmin("2.0", "/search?q=" + ("SELECT * FROM messages where conversation.style='blog' AND depth=0 ORDER BY metrics.views DESC limit 5")?url).data.items![] />

Is it possible to get the post_time of the messages also in view_friendly format like “2 weeks ago”? How?

${mostviewedMessage.post_time } shows “Jul 8, 2016 12:34:13 PM”
${mostviewedMessage.post_time@view_friendly_date} is not working

Thank you, best
Clemens

  • Hi clemensw

    increase the days in below option:
    Admin > System > Date and Time > Number of days to use relative dates
    Ex:1500

    Code:

    <#assign query="SELECT * FROM messages where conversation.style='blog' AND depth=0 ORDER BY metrics.views DESC limit 5"/>
    <#assign mostviewedMessages = restadmin("2.0", "/search?q=" +query?url).data.items/>
    <#list mostviewedMessages as mostviewedMessage>
    ${mostviewedMessage.post_time_friendly}<br>
    </#list>

    • clemensw's avatar
      clemensw
      Guide

      Hi saikumarn

      thank you for your reply, but unfortunately I don't know how to use it.

      How can I get the friendly version of ${mostviewedMessage.post_time} ?

      do I need something like:
      <#assign datesupport.setDate({mostviewedMessage.post_time}) />
      ${datesupport.friendlyDateAsString} ?

      Thanks,
      Clemens

  • clemensw

    Use below code to fetch post friendly time using your query.

    ${mostviewedMessage.post_time_friendly}

     

     

    • clemensw's avatar
      clemensw
      Guide

      Hi Parshant

      unfortunately it's not working:

      when we use: ${mostviewedMessage.post_time_friendly}
      we get:

      The following has evaluated to null or missing:
      ==> mostviewedMessage.post_time_friendly  [in template "preview" at line 38, column 75]

      when we use:

      <#if mostviewedMessage.post_time_friendly??>
      ${mostviewedMessage.post_time_friendly}
      <#else>
      ${mostviewedMessage.post_time?datetime?string}
      </#if>

       we get e.g.: Jul 8, 2016 12:34:13 PM

      It seems that ${mostviewedMessage.post_time_friendly} is empty.
      How can we convert it to a friendly version?
      How can we convert it to a version without time, only date?

      Regards,
      Clemens

      • Parshant's avatar
        Parshant
        Boss

        clemensw,

        Update these settings in your community from Community Admin:

        Admin >  System > Date and Time > Display dates as

        relative_time.PNG

         

         

  • Hi clemensw

    increase the days in below option:
    Admin > System > Date and Time > Number of days to use relative dates
    Ex:1500

    Code:

    <#assign query="SELECT * FROM messages where conversation.style='blog' AND depth=0 ORDER BY metrics.views DESC limit 5"/>
    <#assign mostviewedMessages = restadmin("2.0", "/search?q=" +query?url).data.items/>
    <#list mostviewedMessages as mostviewedMessage>
    ${mostviewedMessage.post_time_friendly}<br>
    </#list>