Skip to content
Franco Mussopower pages
Neon pink and purple light particles
Photograph · Jr Korpa / Unsplash
Guide No.029
TutorialLiquid

Date Validation – Comparing Dates in Liquid

In this quick tip, we’ll see how to check whether a given date is earlier than today’s date (or another specific date).

Level
03CustomiseStage 3 of 4
Read
4 min
Includes
2 snippets
Written
Mar 2023

In this quick tip, we’ll see how to check whether a given date is earlier than today’s date (or another specific date). I’ll compare a date column from Dataverse to today’s date but this method could just as easily be used to compare 2 date columns from Dataverse.

This is something I found a little tricky when I was getting started with liquid. I expected there would be a datediff function but no, so how do we work around this?

Liquid - Comparing DatesLiquid
{% if date_to_check <= expiry_validation_date %}
    {{ date_to_check }}
{% else %}
    <span class="glyphicon glyphicon-alert" aria-hidden="true"></span> {{ date_to_check }}
{% endif %}

Read on if you’re interested in how I arrived at this code…

Please note that this simplified approach is suitable for comparing dates only (times won’t be considered as they’d produce a number too big for liquid to handle)

Transforming values

In liquid, we can use filters to transform values into various different formats (see https://learn.microsoft.com/en-us/power-apps/maker/portals/liquid/liquid-filters#date-filters for the available options).
So, how do we filter? Just type a pipe character | after the value, followed by the name of the filter – in our example, that’s date.
If the filter accepts any parameters, we type a colon and then pass the parameters, like so:
{{ now | date: 'yyyyMMdd' }}

(As you can see, getting the current date and time is nice and easy. We use the now keyword.)

Assign the date to a variable for easy reuse

We’ve got a decent starting point BUT we can’t really ‘do’ anything with the result yet other than output on the page. Let’s fix that by assigning it to a variable…
{% assign current_date = now | date: 'yyyyMMdd' | integer %}
With our filters (transformations), current_date now reads something like so: 20230306

In my example, I want to check the Expiry Date column from my Royalty Agreements table in Dataverse. I’ll give that the same treatment; assign to a variable and transform:
{% assign date_to_check = result.musdyn_expirydate | date: 'yyyyMMdd' | integer %}

Now to compare them…

We can then compare with simple operators like:

Symbol Description
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
== Equal to

So let’s see how to check whether a date is in the past
{% if date_to_check < current_date %}

Taking this a step further… what if we want to check a date is within a certain period?

Example: is expiry date within the next 30 days?

We’ll start with today’s date and add 30 days. For this we have the very handy date_add_days filter

{% expiry_validation_date = now | date_add_days: 30 %}
{% expiry_validation_date = now | expiry_validation_date | date: 'yyyyMMdd' | integer %}

…and then compare using if
{% if date_to_check >= expiry_validation_date %}

In this example, I’ll output a warning icon for expiry dates falling within the next 30 days:

Liquid - Comparing DatesLiquid
{% if date_to_check <= expiry_validation_date %}
    {{ date_to_check }}
{% else %}
    <span class="glyphicon glyphicon-alert" aria-hidden="true"></span> {{ date_to_check }}
{% endif %}
Go deeper · Power Pages Mastery

This guide is one technique. The course is the method.

The course covers this in Level 3 · Advanced customisation: “Liquid templating for dynamic components”, alongside “Transforming out-of-the-box lists”. A structured programme distilled from dozens of real portal launches — from messy stakeholder requirements to successful go-live.

  • 6 weeks
  • 3 levels
  • Live training + video lessons
Where this fits
  1. Level 1Foundations
  2. Level 2Extending the platform
  3. Level 3Advanced customisation
    • Liquid templating for dynamic components
    • Transforming out-of-the-box lists
There is a knowledge gap when we go from traditional Power Apps work to Power Pages. Franco’s depth of platform knowledge, creative problem-solving, and understanding of web design makes using him to skill up a team a no-brainer.
Tyler Page — Director & Solution Architect — MCA Connect
Filed underLiquid

1 comment

  1. Mariusz

    Can I change (rename) one the power pages form the field label text ? e.g. on D365 form field calls “Customer”, on portal pages form I would like to call field label “Client”. Is it possible ?

Leave a comment

Your email address won’t be published. Comments are moderated.

Consulting

Need a Power Pages build that editors love and brands survive?

I help teams design and build Power Pages sites with bespoke UX. Tell me about yours.

Search

Book a discovery call

30 minutes. Bring your trickiest Power Pages problem — I’ll tell you honestly whether I’m the right fit.