Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Created December 19, 2024 17:41
Show Gist options
  • Save NickDeckerDevs/60807bae86fac802c95009dcc53a366d to your computer and use it in GitHub Desktop.
Save NickDeckerDevs/60807bae86fac802c95009dcc53a366d to your computer and use it in GitHub Desktop.
I'm going to respond here and talk through some of the issues that make this difficult to do in HubSpot
so, to get today's date we use `{{ local_dt }}` -- and we could just covert that to a timestamp using `{{ local_dt|unixtimestamp }}` and that would give me a unixtimestamp that I can use, but we really need "midnight" because we need the start of the today if we want to know if anything was updated today.
In the code below I'm going to use the `|pprint` filter, which will show us what "types" these variables are as we convert them
```
<p>local_dt|pprint: {{ local_dt|pprint }}</p>
{# output: local_dt|pprint: (PyishDate: 2024-12-19 12:24:03) #}
<p>local_dt|format_date('M/d/yy'): {{ local_dt|format_date('M/d/yy')|pprint }}</p>
{# output: local_dt|format_date('M/d/yy'): (String: 12/19/24) #}
<p>local_dt|format_date('M/d/yy')|strtodate('M/d/yy'): {{ local_dt|format_date('M/d/yy')|strtodate('M/d/yy')|pprint }}</p>
{# output: local_dt|format_date('M/d/yy')|strtodate('M/d/yy'): (PyishDate: 2024-12-19 00:00:00) #}
<p>local_dt|format_date('M/d/yy')|strtodate('M/d/yy')|unixtimestamp: {{ local_dt|format_date('M/d/yy')|strtodate('M/d/yy')|unixtimestamp|pprint }}</p>
{# output: local_dt|format_date('M/d/yy')|strtodate('M/d/yy')|unixtimestamp: (Long: 1734566400000) #}
```
So now we have this midnight date/time stamp that we can use < = or > or some combination.
Second problem here? When using this call `{% set product = crm_object("product", "12344", "name,price,hs_lastmodifieddate,createdate") %}`
these dates aren't actually a PyishDate OR a LONG -- so we are going to convert that
```
{% set updated_date = product.hs_lastmodifieddate|strtodate('M/d/yy')|unixtimestamp %}
{% set created_date = product.createdate|strtodate('M/d/yy')|unixtimestamp %}
```
Then that allows to get this filter in the if statement figured out
```
{# top of code block #}
{% set midnight_today = local_dt|format_date('M/d/yy')|strtodate('M/d/yy')|unixtimestamp %}
{# inside your for loop #}
{% if(createdDate >= midnight_today || updatedDate >= midnight_today) %}
<h2>{{ product.name }}</h2>
<p>Updated: {{ product.hs_lastmodifieddate|pprint }}</p>
<p>created: {{ product.createdate|pprint }}</p>
{% endif %}
```
I was solving this filtering, and I'm not sure why you wouldnt want to try to filter this on the crm_objects call -- so I'm going to work on that now so that it is a bit simplified.
- Do we really need to do create/last modified? I think we only need last modified
- so can we do this in the query and reducing the coding?
I'll be back a bit later.
Here is a sample block of code to save https://gist.github.com/NickDeckerDevs/ce4896cce76fb9e9d473083d68491481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment