Checking to see if a date has expired

DM2
Participant

Hi I'm trying to check if a datetime stamp has expired. I've set two variables that correctly pull the date to be checked (end_date) and the current date (current_date):

 

{% set current_date = unixtimestamp(local_dt) | format_datetime('medium', local_time_zone) %}
{% set end_date = module.end_date_and_time | format_datetime('medium', local_time_zone) %}
      
  {% if current_date >= end_date  %}
     the date has expired
  {% else %}
     the date has yet to pass
  {% endif %}   

 

 

This doesn't work though - could anyone point me in the right direction please?

 

Thanks!

0 Upvotes
1 Accepted solution
Jaycee_Lewis
Solution
Thought Leader

Hey, @DM2 👋 What if we tried comparing Unix timestamps directly? Meaning,

{% set current_timestamp = unixtimestamp(local_dt) %}
{% set end_timestamp = unixtimestamp(module.end_date_and_time) %}

vs

{% set current_date = unixtimestamp(local_dt) | format_datetime('medium', local_time_zone) %}
{% set end_date = module.end_date_and_time | format_datetime('medium', local_time_zone) %}

 

So that we are comparing the actual numeric vales and not formatted date strings.

 

Please let us know if you get it working.

 

Have fun building! — Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




View solution in original post

2 Replies 2
DM2
Participant

 thank you @Jaycee_Lewis that works perfectly.

0 Upvotes
Jaycee_Lewis
Solution
Thought Leader

Hey, @DM2 👋 What if we tried comparing Unix timestamps directly? Meaning,

{% set current_timestamp = unixtimestamp(local_dt) %}
{% set end_timestamp = unixtimestamp(module.end_date_and_time) %}

vs

{% set current_date = unixtimestamp(local_dt) | format_datetime('medium', local_time_zone) %}
{% set end_date = module.end_date_and_time | format_datetime('medium', local_time_zone) %}

 

So that we are comparing the actual numeric vales and not formatted date strings.

 

Please let us know if you get it working.

 

Have fun building! — Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More