CMS Development

rainism
Member

Comparing two dates

Hello.

I've created a date and time type of column in my table to filter my data by date. I also use this column to group and sort the content by time so I don't really want to create a column for a date only.

Anway, now I can't filter my data by date. 

 

When I convert this column into unixtimestamp, it simply filters not only by date but also by time. I don't really need filtering by time 

{% set local = unixtimestamp(dt) %}

{% if (row['mycolumn']|unixtimestamp) >= (local) %}
print my data
{% endif %}

But when I try to apply the datetimeformat filter, it hides everything except for the content with the today's date. 

Also, yesterday it seemed to work pretty correct. But maybe it's me who's doing something wrong.

 

{% set local = unixtimestamp(dt) %}
{% set timestamp = local|datetimeformat('%b %e') %}

{% if (row['mycolumn']|datetimeformat('%b %e')) >= (timestamp) %}
print my data
{% endif %}

 

Also, I've added a date column to try filtering by date only, but everything is pretty much the same.

0 Upvotes
6 Replies 6
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Comparing two dates

Hey @rainism 

 

Have you tried the 'between_times' filter?

 

We used this a few weeks back. You can see it here.

 

This is assuming that you're storing the date as Hubspot sets it, and not another format.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
rainism
Member

Comparing two dates

I just tried it, but I don't know if I should convert my date and time type of column into unixtimestamp or apply the datetimeformat filter.

When I try to set a variable for this column, it just prints null.

0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Comparing two dates

So I like to avoid transforming any data, especially before a comparision until I absolutelty need to display it to the user. This helps with debugging as you ideally will be comparing data and not its formating or improper formating. With that said that's not always possible and depends entirely on how that data is formated when stored.

 

Interesting that you're gettying a null value when printing the data. I would suggest printing all of your data to a test page to check that you are actually getting the data you expect, and then analyze the format of said data.

 

I like to draw the use of data to that of repairing an old car. With old cars you check 2 things first: fuel and spark or in our case data in and the functions that use the data. Check that the data/fuel is the correct type (don't put diesel in a standard gas car) and check that it is available at the correct location(your page). Once you know that these are correct and you're still seeing an issue its time to check that your spark or functions are working as expected. Narrow the scope of your search and it should get easier to pin-point the real issues.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
rainism
Member

Comparing two dates

Finally found where my problem was!

 

I only have one question left: is it possible to set a specific timezone instead of local_dt?

I've tried to substract milliseconds from the local variable, but I don't think it's working and I don't think it's  the right thing to do.

 

{% set local = local_dt %}
{% set current = local - 18000000 %}
0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Comparing two dates

Yep you can set it with the datetime format

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
rainism
Member

Comparing two dates

Well, that's strange because my local_dt variable shows my Hubspot timezone, but my content disappears when it's 00:00 (UTC+00).
Wonder what I'm doing wrong.

0 Upvotes