• 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 using date in math function

Explorer ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

I'm trying to check if the month in a date (in format "MM") is <7 but the code only seems to be calculating for the {% else -%} part of the code. I've tried using brackets and no brackets but neither seem to work.

{% assign newMonth = globals.site.dateNow | date_add: 1, "month" -%}

{% assign newYear = globals.site.dateNow | "yyyy" -%}

{% assign newDay = "01"  -%}

<p>newMonth : {{newMonth | date: "MM"}}</p>

{% if newMonth | date: "MM" | convert: "number" | json < 7 -%}

<p>Retrospective Date is: {{newDay}}-{{newMonth | date: "MM"}}-{{newYear | date_add: -3, "year" | date: "yyyy"}}</p>

{% else -%}

<p>Retrospective Date is: {{newDay}}-{{newMonth | date: "MM"}}-{{newYear | date_add: -2, "year" | date: "yyyy"}}</p>

{% endif -%}    

TOPICS
Developer

Views

527

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

correct answers 1 Correct answer

Explorer , Sep 07, 2017 Sep 07, 2017

I've never gotten reliable results using filters in an IF tag, and usually create a simple var to test prior to entering the IF.

Votes

Translate

Translate
Explorer ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

I've never gotten reliable results using filters in an IF tag, and usually create a simple var to test prior to entering the IF.

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 ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

I'd like to add in a text picker so I can run tests on various dates. I've got this far but can't get anything from the input field

Enter Date to test

     <input name="test" id="test" class="cat_textbox" readonly="readonly" style="background-color: #f0f0f0;" onfocus="displayDatePicker('test');return false;" type="text" />

    

                

                   

        <h2>Fields that will be calculated (these will be hidden)</h2>

       

        {% assign startDate =  test.value | convert: "date"  -%}

Is this possible in liquid or do I have to use 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
Explorer ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

It depends on where the test is being run and what data is being used.

Liquid is a markup processing language - it's used to dynamically construct the page before it's sent to the user - only the server understands it (most of the time).

Once the page has been rendered and sent to the client's browser, liquid is out of the picture, and any logic performed at the browser needs to be done using standard web technology - javascript/jquery/angular/css/etc

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 ,
Sep 08, 2017 Sep 08, 2017

Copy link to clipboard

Copied

LATEST

THanks again - thats a good explanation.

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 ,
Sep 07, 2017 Sep 07, 2017

Copy link to clipboard

Copied

Thanks! That did the trick

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