CMS Development

narmstrong
Mitwirkender/Mitwirkende | Platinum Partner
Mitwirkender/Mitwirkende | Platinum Partner

HubDB Date Comparison error

Hello,

I am comparing formated date times from HubDB to add specific class names for sorting purposes. The following code is the comparison piece. Also of note the following code IS within the forloop that gets the values from the database.

 

 

 

 

 {% set isthisweek = row.end_date|datetimeformat('%U') %} 
 {% set isthismonth = row.end_date|datetimeformat('%m') %} 
 {% set isthreemonths = row.end_date|plus_time(2, 'months') %} 
 {% set thisweek = local_dt|datetimeformat('%U') %}
 {% set thismonth = local_dt|datetimeformat('%m') %}
 {% set thisthree = local_dt|plus_time(2, 'months') %}

{% if isthisweek == thisweek %}
  {% set mydate = 'this-week this-month three-months' %}
{% elif (isthismonth == thismonth) != false %}
  {% set mydate = 'this-month three-months' %}
{% elif thisthree|between_times(isthreemonths, 'months') > 0 and thisthree|between_times(isthreemonths, 'months') <= 2 %}
  {% set mydate = 'three-months' %}
{% elif thisthree|between_times(isthreemonths, 'months') > 2 %}
  {% set mydate = 'more-than-three' %}
{% endif %}

 

 

 

 

My problem is that comparing the variables isthisweek to thisweek is not making logical sense. For example I have a class set for "this-week" if the two are equal. When using this however I have "card" with a week value of 04 (which is this week 01/21/2021[eg today]) and another for 02/09/2021 which is week 07. The February event is getting the class this-week for some reason I cannot fathom.

I have also tried the following comparison operation:

 

 

//Original
{% if isthisweek == thisweek %}
  {% set mydate = 'this-week this-month three-months' %}

//Also Tried
{% if (isthisweek - thisweek) == 0 %}
  {% set mydate = 'this-week this-month three-months' %}

{% if (isthisweek|int - thisweek|int) == 0|int %}
  {% set mydate = 'this-week this-month three-months' %}

{% if isthisweek|int == thisweek|int  %}
  {% set mydate = 'this-week this-month three-months' %}

 

 

None of these seem to work. If anyone has anythoughts on this I would like to hear them as I am currently stuck.

 

Thanks in advance.

Noah Armstrong | TSL Marketing
Senior Developer
6085 Marshalee Dr| Suite 100 | Elkridge, MD 21075
Contact Us

TSL Marketing
0 Upvotes
2 Antworten
natsumimori
Community-Manager/-in
Community-Manager/-in

HubDB Date Comparison error

Hi @narmstrong ! Thank you for posting your question:)

 

@alyssamwilie and @Kevin-C , is this topic something you guys are familiar with? Would you mind sharing your advice for @narmstrong ?

0 Upvotes
Kevin-C
Trendsetter/-in | Partner
Trendsetter/-in | Partner

HubDB Date Comparison error

Hey @narmstrong 

 

I was unable to recreate this error. Is this issue still happening?

 

If so, maybe you're declaring the "mydate" somewhere else and have the scope confused?

Kevin Cornett - Sr. Solutions Architect @ BridgeRev