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

Liquid - Using date

Guide ,
Dec 27, 2014 Dec 27, 2014

In the docs it says this:

date Here are the available switches:
  • %d - outputs the day of the month - 18
  • %M - outputs the month of the year - 6
  • %y - outputs the year - 14

To output 14-06-18 use {{dateVariable | date: "%y-%M-%d"}} (mind the double quotes).

I then try the following on my site: {{dateVariable | date: "%y-%M-%d"}} when it renders on the site it shows like this: {{dateVariable}}.


Is this a bug or are the docs incorrect?


While on the topic of date is there no way to get the Day of the Week? IE: Sunday, Monday, etc.


For that matter will we have all of the options available that Liquid has? I was looking at the Shopify Liquid docs on date. Will be be able to access all of these?

TOPICS
Developer
3.1K
Translate
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 , Dec 27, 2014 Dec 27, 2014

Hi Lynda,

Where are you getting the date value from? I mean what date do you assign to the "dateVariable" variable? If possible please let me know a sample page where you have this setup implemented, I will have a look,

The date switches at the Shopify page will not work because we are using a different Liquid implementation. From the next release however we will add alot of new date type filters, almost all of the switches here will work: Custom Date and Time Format Strings

Thanks,

Mihai

Translate
Engaged ,
Dec 27, 2014 Dec 27, 2014

Hi Linda,

To answer your last question (without a clue, mind you), I'm sure we'll eventually be able to use the rest of the date filters, but I doubt they are very high up the list of priorities right now. That said, it could be a nice feature request to add to the ideas.

Was your dateVariable outputted from a date-time field in a BC module?

Translate
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 ,
Dec 27, 2014 Dec 27, 2014

Hi Lynda,

Where are you getting the date value from? I mean what date do you assign to the "dateVariable" variable? If possible please let me know a sample page where you have this setup implemented, I will have a look,

The date switches at the Shopify page will not work because we are using a different Liquid implementation. From the next release however we will add alot of new date type filters, almost all of the switches here will work: Custom Date and Time Format Strings

Thanks,

Mihai

Translate
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
Guide ,
Dec 28, 2014 Dec 28, 2014

Hi Mihai,

I think I may be using it incorrectly. If I wanted to spit out just the year how would I do that?

I will be looking forward to the next release! Adding more date and time switches will be great!

Thank You!

Translate
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
Guide ,
Dec 28, 2014 Dec 28, 2014

I just realized I wasn't actually defining the variable. Oops! It is working now. I am looking forward to the new date features! Have many uses for them.

Translate
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 ,
Dec 28, 2014 Dec 28, 2014

With the next release we will have methods for outputting the current date as well. You will be able to build something like "show me the products released in the last 2 days". We will build how to articles for the date scenarios as soon as they're out.

Happy holidays,

Mihai

Translate
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
Guide ,
Dec 29, 2014 Dec 29, 2014

Awesome! Very useful. Looking forward to it! Thank You!

Happy Holidays!

Translate
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
Engaged ,
Jan 06, 2015 Jan 06, 2015

Woohoo!! New date filters for Liquid! Thanks BC team!

Translate
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 ,
Jan 06, 2015 Jan 06, 2015

I actually saw that this morning too Adam, about another 30 date filter options available to us.

Definitely a Woohoo moment!

Translate
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 ,
Jan 07, 2015 Jan 07, 2015

Hi guys,

The new date switches will be available from the next release (early next week). We'll have some more how to articles and samples for date comparisons and rendering options

Thanks,

Mihai

Translate
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
Guide ,
Jan 07, 2015 Jan 07, 2015

Awesome! Looking forward to the next release.

Translate
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 ,
Jan 14, 2015 Jan 14, 2015

Any news on this?

I would like to be able to have a variable that could show the current date and month seperately.

I would think that i could use the "old" {module_today} and "split" them up, but this sounds much nicer.

I am doing a birthday app, that can display employees birthday on a "internal" website for a client of mine.

At the moment i am working on something like this:

{% for item in items %}

{% if {{item.['Birthday-month']}} contains "January" %}

{% if {{item.['Birthday-day']}} contains "13" %}

<div class="birthday">

        <div class="name">Happy birthday to  {{item.name}}</div>

</div>

{%endif %}

{%endif %}

{%endfor%}

Where "January" and "13" should be the current date variable.

Not sure if this is the way to do it, but works so far

Translate
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 ,
Jan 14, 2015 Jan 14, 2015

Just look at Cristenels post Peter. See whats in the next release. You already have filters for data you can see on the doc reference.

Translate
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 ,
Jan 14, 2015 Jan 14, 2015

Hi Liam

Is it first possible to do this tomorrow after the update, or is it possible with the current filters to get current month and date?

I've been using {{releaseDate | date: "%d"}} for some other things on the site, but is there a similar one to display current date available now?

Translate
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 ,
Jan 14, 2015 Jan 14, 2015

Not till the release because the global object will contain the system date. You can use that and the proper iso time stamp for an item and compare them properly.

Translate
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 ,
Jan 14, 2015 Jan 14, 2015

Great. That was what i understood from reading the post, but didn't know if I had missed something.

I'll just have to wait until tomorrow. Nearly perfect timing though!

Translate
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 ,
Jan 20, 2015 Jan 20, 2015

This is awesome, works great.

I have done this, and works fine. (maybe the code could be nicer?)

{% assign birthdayDay = Globals.Site.DateNow| date: "%d" %}

{% assign birthdayMonth = Globals.Site.DateNow| date: "%M" %}

{% for item in items %}

{% assign birthdayYear = {{item.['Birthday-year']}} %}

{% if {{item.['Birthday-month']}} == birthdayMonth %}

{% if {{item.['Birthday-day']}} == birthdayDay %}

<div class="birthday">

    <br>

    <div class="name">Happy birthday to {{item.name}}</div>

    <br>

</div>

<br>

<br>

{%endif %}

{%endif %}

{%endfor%}

Just a question.

I can get this tag working fine {{Globals.Site.DateNow| minus: "2015-01-15"| date: "%d"}}.

It is great that it is now possible to calculate, but what if I want to calculate with a "variable".

The thing I want to achieve is that you also can display how old the person is on his/hers birtday.

I've made this {% assign birthdayYear = {{item.['Birthday-year']}} %}

And i thought I could combine it with {{Globals.Site.DateNow| minus: "2015-01-15"| date: "%d"}}

in something like {{Globals.Site.DateNow| minus: {{birthdayYear}}| date: "%y"}} or something like that,

but I can't get it to work, I think that the format on the two dates i am trying to compare is not working,

because I am trying to compare a "complete" date with only the year.

Hope it makes sense, and somebody can give me a pointer

Translate
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 ,
Jan 20, 2015 Jan 20, 2015

and is now there for your if statements as a note

But what your after is the inclusion of data types in BC as of the latest release

http://docs.businesscatalyst.com/developers#!/liquid/datatypes

So you can convert your custom text field to a data and then run your checks, in fact you can do heaps. BC did an awesome job on this stuff!

Translate
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 ,
Jan 20, 2015 Jan 20, 2015

THX LIAM!

Just what i needed. Didn't notice the "convert" before you pointed me in the right direction.

Ended up with this and it seems to be working

{% assign birthdayDay = Globals.Site.DateNow| date: "%d" %}

{% assign birthdayMonth = Globals.Site.DateNow| date: "%M" %}

{% for item in items %}

{% assign birthdayYearVar = {{item.['Birthday-year']}} | convert: "number" %}

{% assign birthdayCalc = globals.site.dateNow | date: "yyyy" | minus: birthdayYearVar %}

{% if {{item.['Birthday-month']}} == birthdayMonth %}

{% if {{item.['Birthday-day']}} == birthdayDay %}

<div class="birthday">

    <br>

    <div class="name">Happy birthday to {{item.name}}</div>

    <br>

    <br>{{item.name}} turns {{birthdayCalc}} years old today.

</div>

<br>

<br>

{%endif %}

{%endif %}

{%endfor%}

Thx again Liam!

Translate
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 ,
Jan 20, 2015 Jan 20, 2015

No Problem, have a go at using and as well and you can get that code even tidier. Worth doing. New stuff, get into the habit earlier the better.

Also see the minus sign at the end of this example below? This means it will supress the white space in your markup. View the page source where you just did the above, you will see what it looks like without

{% if {{item.['Birthday-month']}} == birthdayMonth -%}



Translate
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 ,
Jan 20, 2015 Jan 20, 2015
LATEST

Thx Liam, I will look into that!

Translate
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