The first step is to get your "now" date properly formatted!
{% assign today = "now" | date: "%s" %}
In this scenario I used a custom field named last_week_donation
to retrieve the last donation date. The value in the database is "2020-05-15" (today is the 17th).
{% assign this_week_donation_date = subscriber.last_week_donation | date: "%s" %}
{% assign less_than_a_week_donation_gap = today | minus: this_week_donation_date | divided_by: 3600 | divided_by: 24 %}
{% if less_than_a_week_donation_gap < 7 %}
Hey, you donated this week! Thank you!
{% else %}
C'mon, it's been way too long!
{% endif %}
Notice that this first section is just to assign a new variable. The main relevant difference is that I'm pulling info from another custom field, this time named last_month_donation
. The value in the database is "2020-04-15".
I have added a comment below as to why I changed this.
{% assign this_month_donation_date = subscriber.last_month_donation | date: "%s" %}
{% assign more_than_a_week_donation_gap = today | minus: this_month_donation_date | divided_by: 3600 | divided_by: 24 %}
{% if more_than_a_week_donation_gap < 7 %}
Hey, you donated this week! Thank you!
{% else %}
C'mon, it's been way too long!
{% endif %}
This is a "testing use case" for ConvertKit and I had to play around with different fields because I wanted to test this in one go and, apparently, I can't reassign the a variable inside one email.
This would never be the production-ready code.
In real world use cases you'd probably have a field {{ subscriber.last_donation_date }}
that would be updated everytime the subscriber made a donation, you'd only go through these calculations once and all those "assign variables" would be cleaner.
Here's the entire code used on the email to test this live:
{% assign today = "now" | date: "%s" %}
"You're so nice" check
{% assign this_week_donation_date = subscriber.last_week_donation | date: "%s" %}
{% assign less_than_a_week_donation_gap = today | minus: this_week_donation_date | divided_by: 3600 | divided_by: 24 %}
{% if less_than_a_week_donation_gap < 7 %}
Hey, you donated this week! Thank you!
{% else %}
C'mon, it's been way too long!
{% endif %}
"It's been too long" check
{% assign this_month_donation_date = subscriber.last_month_donation | date: "%s" %}
{% assign more_than_a_week_donation_gap = today | minus: this_month_donation_date | divided_by: 3600 | divided_by: 24 %}
{% if more_than_a_week_donation_gap < 7 %}
Hey, you donated this week! Thank you!
{% else %}
C'mon, it's been way too long!
{% endif %}
{% capture unused %}
{% assign today = "now" | date: "%s" %}
{% assign last_donation_date = subscriber.last_donation_date | date: "%s" %}
{% assign days_since_last_donation = today | minus: last_donation_date | divided_by: 3600 | divided_by: 24 | minus: 8 | append: "" | first %}
{% endcapture %}
{% if subscriber.last_donation_date == blank %}
You have never donated before 😭
{% else %}
{% if days_since_last_donation == "-" %}
Hey, you donated this week! Thank you! 🥰
{% else %}
C'mon, it's been way too long! 😢
{% endif %}
{% endif %}