Comparing time with current time in liquid

Tourist
39 0 3

So, I'm trying to make it more obvous to our customer that we have a 12 noon cut off point for next day delivery.
On the product template, I'm trying to add the following....

  {% assign cut_off = "12:00" | convert: "date" %}
           {% capture now_time %} {{'now' | date: "%H:%M" }}{% endcapture %}
           {% if now_time <= cut_off %}
           <p> Order now for delivery tomorrow </p>
          

I've tried different ways where I though I could get this to work with no joy. Any liquid savvy person know the solution to this please?

Thank you

1 Like
Highlighted
Shopify Partner
25 7 10

Did you sold the problem, by any chance ?

0 Likes
Highlighted
Shopify Expert
9819 92 1581

You should avoid using Liquid to compare current times. For that you'll need to use JavaScript instead. The now time will be time of cache, and may not be the actual now time so it's risky to rely on.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
3 Likes
Highlighted
New Member
1 0 0
 
{% assign wday = 'now' | date: "%a" %}
{% if wday == 'Thu' %}
{% assign days = 2 | times: 86400 %}
{% else %}
{% assign days = 1 | times: 86400 %}
{% endif %}
{% assign deliverydate = 'now' | date: "%s" | plus: days | date: "%Y-%m-%d" %}
 
GET IT TOMORROW! ORDER WITHIN <span id="time">{{ deliverydate }}</span> 
 
Use countdown jquery or javascript function to start countdown
 
 
         
You can change wday to {% if wday == 'Sat' or wday == 'Sun' %}
 
 
 

@Tom98 wrote:

So, I'm trying to make it more obvous to our customer that we have a 12 noon cut off point for next day delivery.
On the product template, I'm trying to add the following....

  {% assign cut_off = "12:00" | convert: "date" %}
           {% capture now_time %} {{'now' | date: "%H:%M" }}{% endcapture %}
           {% if now_time <= cut_off %}
           <p> Order now for delivery tomorrow </p>
          

I've tried different ways where I though I could get this to work with no joy. Any liquid savvy person know the solution to this please?

Thank you


0 Likes
Highlighted
Shopify Partner
8 0 2

Hi

 

I have used this to compare with time 15:30:

{% capture now_time_H %} {{'now' | date: "%H" }}{% endcapture %}
{% capture now_time_M %} {{'now' | date: "%M" }}{% endcapture %}
{% assign now_time = now_time_H | times: 100 | plus: now_time_M %}
{% if now_time >= 1530 %}
<span>message</span>
{% endif %}

0 Likes