0

I'm trying to find the date and time difference between two unix values. In HuBL, I have currently:

{% set event_date_and_time = table_data_dict.event_time|unixtimestamp %}
{% set current_time_and_date = local_dt|unixtimestamp %}

{% if current_time_and_date  >= event_date_and_time %}
  event is live
{% else %}
  event is not live
{% endif %}

table_data_dict.event_time is the value from the date and time field in the database.

Running the following:

Event: {{ event_date_and_time }} <br>
Current: {{ current_time_and_date }}

Produces the following results:

Event: 1596623700000
Current: 1596620020929

Test scenarios:

Test 1:

The date and time I have set in the database (what event_date_and_time is) is 10th August 2020 12pm.

The if statement echos event is not live - which is correct.

Test 2:

The date and time now, in the database is set to a day before todays date (so 4th august 2020 12:00pm) - the event is essentially live.

The if statement echos event is live - which again, is correct.

Test 3:

Now, currently for me, it's 11:00am (5th Aug 2020). If, in the database, I change the date and time to 5th August 2020 11:10am. It produces the following results:

At 10:55am, when I check the if statement, it will say event is not live (correct, it's live at 11am).

Now, when I check at 11am (when the event is live) it says event is not live.

When I continue to wait and check again at 11:05am, it still says event is not live.

Unsure why? I have cleared cache, it's not a caching issue, unsure why it's performing like so?

Freddy
  • 683
  • 4
  • 35
  • 114
  • Because you set "11:10" and not "11:05" ? A debugging hint: write also both timestamps: it helps to see problems (timezones is often one of them). – Giacomo Catenazzi Aug 05 '20 at 10:08
  • @GiacomoCatenazzi - What I've realised is that it doesn't work if the date the day is on, is todays date. For example, todays date is 5th August. If the field is set to 4th Aug, it will show event event live. If the event date is 6th Aug, it will show event is not live. BUT, if the event date is set to 5th Aug (todays date), then it will show event is not live ... – Freddy Aug 05 '20 at 10:43
  • 1
    @Freddy because your event will only be live as from one specific second, the exact second of your event in your DB: (e.g. Aug 5th 2020, 11:00:00) – β.εηοιτ.βε Aug 05 '20 at 11:30
  • @β.εηοιτ.βε - But why is that? I've defined greater than or equal to `>=` in my if statement? – Freddy Aug 05 '20 at 11:34

0 Answers0