Liquid Comparison Date

I want to compare two dates. I want to create a condition that checks if the date in my database is older than the date two days later.

Here are my two variables:

{<f:format.date format="d.m.Y">+2 days</f:format.date>}
{<f:format.date format="d.m.Y">{day.valid}</f:format.date>}

I want to solve this in a template, not in a model or controller.

+5
source share
4 answers
<f:if condition="{f:format.date(date: '+2 days' format: 'Y-m-d')} < {f:format.date(date: yourdate, format: 'Y-m-d')}">
<f:then>
   yourdate is smaller than now + 2 days.
</f:then>
<f:else>
    yourdate is greater than now + 2 days.
</f:else>
</f:if>
+9
source

Convert date to unix timestamp with format="U"and compare them. You need to add a variable that contains the date of comparison.

<f:if condition="{f:format.date(date: day.valid, format: 'U')} > {f:format.date(date: date_compare, format: 'U')}">
    Date is valid
</f:if>
+1
source

, .

:

$this->view->assign('date_now', new \DateTime());

{date_now} , :

<f:if condition="{f:format.date(date: date_now, format: '(Y-m-d)')} > {f:format.date(date: '{event.date}-4 weeks', format: '(Y-m-d)')}">
   <f:then>
      <p>Event date is past</p>
   </f:then>
   <f:else>
      <p>Event date is upcoming</p>
   </f:else>
</f:if> 

, , , ('{event.date}-4 weeks').

PS Y-m-d U , - .

+1

: DateTime getTimestamp (http://php.net/manual/en/datetime.gettimestamp.php, 5.3.0), getter Fluid, . $date1 $date2 DateTime :

<f:if condition="{date1.timestamp} < {date2.timestamp}">...</f:if>

unix . $date = (new \DateTime('now'))->modify('+2 days'); Fluid. time() , DateTime.

0

All Articles