Startseite > Template- und Themeprogrammierung > Skriptsprache > Datums Befehle

Datums-Befehle

date

Der <liquid>date</liquid> Filter nimmt ein Timestamp oder ein Datums-String nach ISO 8601(https://de.wikipedia.org/wiki/ISO_8601) entgegen und gibt einen formatierten String mit einer Datumsangabe zurück. Dem Filter wird als Parameter das Pattern für die gewünschte Ausgabe übergeben.

<liquid-input>
{{ '2016-09-16' | date: 'dd.MM.yy' }}
{{ '1473976800000' | date: 'dd-MM-yyyy' }}
{{ 'now' | date: 'dd.MM.yy HH:mm:ss' }}
</liquid-input>
<liquid-output>
16.09.16
16-09-2016
</liquid-output>

<liquid-input>
{{ '2016-09-16' | date: 'y' }}
{{ '2016-09-16' | date: 'yy' }}
{{ '2016-09-16' | date: 'yyyy' }}
</liquid-input>
<liquid-output>
16
16
2016
</liquid-output>

<liquid-input>
{{ '2016-09-16' | date: 'M' }}
{{ '2016-09-16' | date: 'MM' }}
{{ '2016-09-16' | date: 'MMM' }}
</liquid-input>
<liquid-output>
9
09
Sep
</liquid-output>

<liquid-input>
{{ '2011-12-31' | date: 'D' }}
{{ '2012-12-31' | date: 'DD' }}
</liquid-input>
<liquid-output>
365
366
</liquid-output>

<liquid-input>
{{ '2016-09-05' | date: 'd' }}
{{ '2016-09-05' | date: 'dd' }}
{{ '2016-09-05' | date: 'dd' }}
</liquid-input>
<liquid-output>
5
05
05
</liquid-output>

date_add

Der <liquid>date_add</liquid> Filter addiert wahlweise Millisekunden, Sekunden, Minuten, Stunden, Tage, Wochen, Monate oder Jahre zu einem Datum gibt ein neues Datum in einem gewünschten Format zurück.

<liquid-input>
{{ '1474031327866' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 20, 'milliseconds' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 20, 'seconds' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 20, 'minutes' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 20, 'hours' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 20, 'days' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 2, 'weeks' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 12, 'weeks' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_add: 10, 'years' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
</liquid-input>

<liquid-output>
16.09.2016 15:08:47.866
16.09.2016 15:08:47.886
16.09.2016 15:09:07.866
16.09.2016 15:28:47.866
17.09.2016 11:08:47.866
06.10.2016 15:08:47.866
30.09.2016 15:08:47.866
09.12.2016 15:08:47.866
16.09.2026 15:08:47.866
</liquid-output>

date_subtract

Der <liquid>date_subtract</liquid> Filter subtrahiert wahlweise Millisekunden, Sekunden, Minuten, Stunden, Tage, Wochen, Monate oder Jahre von einem Datum gibt ein neues Datum in einem gewünschten Format zurück.

<liquid-input>
{{ '1474031327866' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 20, 'milliseconds' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 20, 'seconds' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 20, 'minutes' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 20, 'hours' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 20, 'days' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 2, 'weeks' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 12, 'weeks' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
{{ '1474031327866' | date_subtract: 10, 'years' | date: 'dd.MM.yyyy HH:mm:ss.SSS' }}
</liquid-input>

<liquid-output>
16.09.2016 15:08:47.866
16.09.2016 15:08:47.846
16.09.2016 15:08:27.866
16.09.2016 14:48:47.866
15.09.2016 19:08:47.866
27.08.2016 15:08:47.866
02.09.2016 15:08:47.866
24.06.2016 15:08:47.866
16.09.2006 15:08:47.866
</liquid-output>

relative_date

Der <liquid>relative_date</liquid> Filter vergleicht 2 Datums Werte miteinander. Die Sprache der Ausgabe entspricht der aktuell ausgewählten Shop-Sprache.

<liquid-input>
{{ 'now' | relative_date: 'now'}}
{{ '05/31/2012' | relative_date: '05/31/2012' }}
</liquid-input>

<liquid-output>
a few seconds ago
a few seconds ago
</liquid-output>

<liquid-input>
{{ 'now' | relative_date: 'now', true }}
{{ '05/31/2012' | relative_date: '05/31/2012', true }}
</liquid-input>

<liquid-output>
a few seconds
a few seconds
</liquid-output>

<liquid-input>
{{ '05/31/2012' | relative_date: '08/20/2012' }}
{{ '05/31/2012' | relative_date: '08/20/2012' }}
</liquid-input>

<liquid-output>
3 months ago
in 3 months
</liquid-output>

<liquid-input>
{{ '05/31/2012' | relative_date: '08/20/2012', true }}
{{ '05/31/2012' | relative_date: '08/20/2012', true }}
</liquid-input>

<liquid-output>
3 months
3 months
</liquid-output>

Kann auch in Kombination mit dem <liquid>date_add</liquid> und dem <liquid>date_subtract</liquid> Filter und "now" als Input benutzt werden.

<liquid-input>
{{ 'now' | date_add: 20, 'seconds' | relative_date }}
{{ 'now' | date_add: 20, 'minutes' | relative_date }}
{{ 'now' | date_add: 20, 'hours' | relative_date }}
{{ 'now' | date_add: 20, 'days' | relative_date }}
{{ 'now' | date_add: 3, 'weeks' | relative_date }}
{{ 'now' | date_add: 12, 'months' | relative_date }}
{{ 'now' | date_add: 500, 'years' | relative_date }}
</liquid-input>

<liquid-output>
in a few seconds
in 20 minutes
in 20 hours
in 20 days
in 21 days
in a year
in 500 years
</liquid-output>

<liquid-input>
{{ 'now' | date_subtract: 20, 'seconds' | relative_date }}
{{ 'now' | date_subtract: 20, 'minutes' | relative_date }}
{{ 'now' | date_subtract: 20, 'hours' | relative_date }}
{{ 'now' | date_subtract: 20, 'days' | relative_date }}
{{ 'now' | date_subtract: 3, 'weeks' | relative_date }}
{{ 'now' | date_subtract: 12, 'months' | relative_date }}
{{ 'now' | date_subtract: 500, 'years' | relative_date }}
</liquid-input>

<liquid-output>
a few seconds ago
20 minutes ago
20 hours ago
20 days ago
21 days ago
a year ago
500 years ago
</liquid-output>