web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

CRM Portal Liquid : How To Do Math Operations On Date?

(0) ShareShare
ReportReport
Posted on by 30

I'm using liquid inside a Microsoft CRM Portal. I want to get the seconds from the date and then do some operations with them, but I'm experiencing a few issues.

  1. In order to get the seconds according to this site: I have to use the filter "%S", but when I do that all I get is the capital letter S. According to the same site if I use the filter "%s" I should get the time in seconds from the epoch, but that actually gives me the seconds. So I'm using the line:

    {% assign seconds = "now" | date:"%s" %}

  2. If I try to use the operation plus: on the result, instead of adding 5, it concatenates 5 at the end. According to this post date returns a string. (In the same, post it also says that math should work on a string if it is only a number and that "%s" should return the unix time, but I can't get these parts to work).

  3. According to this post a string can be converted to an integer by multiplying it by 1 or adding 0. Adding 0 doesn't work, because it concatenates it at the end. On the other hand multiplying by 1 seems to work, but then if I try to add a number to the result, I get an error message : "Liquid error: Parameter count mismatch.

Here is the full code :

{% assign seconds = "now" | date:"%s" %}
{% assign test1 = seconds | plus:5 %}
<p>{{test1}}</p>
{% assign test2 = seconds | times:1 %}
<p>{{test2}}</p>
{% assign test3 = test2 | plus:10 %}
<p>{{test3}}</p>

and Here is the output:

305
30
Liquid error: Parameter count mismatch

I'm pretty sure that I'm doing something wrong, but I can't figure out what. I would really appreciate it if someone could help me figure it out.

Thank you

I have the same question (0)
  • Suggested answer
    dev2143 Profile Picture
    30 on at

    I managed to make it work with :

    {% assign seconds = now | date: '%s' | integer %}

    {% assign test1 = seconds | plus: 5 %}

    credits to jasonscript from stackoverflow.

    stackoverflow.com/.../63050429

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans