• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Help with liquid dateNow

Contributor ,
Oct 06, 2016 Oct 06, 2016

Copy link to clipboard

Copied

Hey BC Community... wondering if anyone can offer some help with the Liquid Date now?

Want to show if the office is closed during a certain time period, that it would output:

- OPEN - for office times of 10am - 4pm

- CLOSED - for office times of 4:01pm - 9:59am

Any suggestions? Still a little green when it comes to liquid, so any code help would be much appreciated. Thanks!

Aaron

TOPICS
Developer

Views

950

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 06, 2016 Oct 06, 2016

Copy link to clipboard

Copied

Use JavaScript for this purpose, in my opinion.

Just know that both BC's liquid date "{{ globals.site.dateNow }}" and JavaScript's "Date.now()" uses the visitors local current time and not the time in your customer's local timezone. So using JS Date.now() you can find the timezone offset using ".getTimezoneOffset()" and work out what the current time is for the local business. Then apply classes for Open / Closed states.

You could use Liquid however I'd suggest placing this calculation overhead onto the visitor using JS.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2016 Oct 06, 2016

Copy link to clipboard

Copied

The above actually is not correct and You should use liquid for this not javascript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 07, 2016 Oct 07, 2016

Copy link to clipboard

Copied

Tip: use 24-hour format for the calculation.

E.G.:

{% assign hour =  globals.site.dateNow | date: "HH" -%}

{% if hour > 10 and hour < 16 -%}

OPEN

{% else -%}

CLOSED

{% endif -%}

Update: Convert your work hours to UTC format and then use date_utc liquid filter to map visitor's timezone with your office time. So above assign would be:

{% assign hour =  globals.site.dateNow | date_utc | date: "HH" -%}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 07, 2016 Oct 07, 2016

Copy link to clipboard

Copied

This is awesome! Thanks UPGR8R and all!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 23, 2017 Aug 23, 2017

Copy link to clipboard

Copied

I am also a newbie with liquid. I have an event with early bird pricing and I want to check if the current date is before the early bird date (so I can only show discount pricing). I've got this far but I think my assignment for Mydate is wrong. The webapp item is called eb-date. Any help appreciated.

{% assign {eb-date}= myDate-%}

{% if globals.site.dateNow < myDate %}

<p>The date is in the future</p>

{%else %}

<p>The date is in the past</p> {% endif %}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

When you're placing a liquid tag, you use double curly brackets to denote a liquid variable, such as {{ eb-date }}.

However, when using liquid logic, such as {% assign -%} or {% if -%}, you don't need to encapsulate your variables in brackets.

So, I think your solution is:

{% assign eb-date = myDate -%}

{% if globals.site.dateNow < myDate -%}

<p>The date is in the future</p>

{% else -%}

<p>The date is in the past</p>

{% endif -%}

Tip: Be more pedantic with your spaces between the liquid tags - BC's rendition of liquid can be unforgiving sometime.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

LATEST

Thanks Stephen

I actually got it to work by just using the liquid tag (as you suggested). This seems to work but I will try it without braces.

{% if globals.site.dateNow < {eb-date} %}

<p>The date is in the future</p>

{%else %}

<p>The date is in the past</p> {% endif %}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines