php - Symfony2 DATEDIFF function -
I need to fill the table in the table with data from the database. Everything is OK with the exception of:
I have a column with the DATEDIFF property to get the number of days.
TODAY-dateFromDateBase
The question is: How to get the number of days in a loop in a twig?
Here's my sprig:
& lt; Table & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Form action = "" method = "post" {{form_enctype (searchform)}} class = "form-index-permit" & gt; & Lt; Td> Lp & lt; / Td> & Lt; Td> ID PRZEPUSTKI {{form_widget (searchform.PermitId)}} & lt; / Td> & Lt; Td> Name {{form_widget (searchform.Permitname)}} & lt; / Td> & Lt; Td> Surname {{form_widget (searchform.Permitsurname)}} & lt; / Td> & Lt; Td> Company {{form_widget (searchform.Company)}} & lt; / Td> & Lt; Td> GW {{form_widget (Search Format Contractor)}} & Lt; Td> Debithe {{form_widget (searchform.Dayleft)}} & lt; / Td> & Lt; Td> End date {{form_widget (searchform.date, {'attr': {'class': 'datepicker'}})}} & Lt; / Form & gt; & Lt; / TR & gt; & Lt; / Thead & gt; {Permitcollection%} permit% lt; Tbody & gt; & Lt; Td> {{Loop.index}} & lt; / Td> & Lt; Td> {{Permit.getPermitid () | Number_format (0, '.', '')}} & Lt; / Td> & Lt; Td> {{Permit.getPermitname ()}} & lt; / Td> & Lt; Td> {{Permit.getPermitsurname ()}} & lt; / Td> & Lt; Td> {{Permit.getPermitsCompany () GetName ()}} & lt; / Td> & Lt; Td> {{Permit.getPermitsContractor (). GetName ()}} & lt; / Td> & Lt; TD & gt; Here I left the day & lt; / Td> & Lt; Td> {{Permit.getExpirationdate () | Date ('Y-M-D')}} & lt; / Td> & Lt; / Tbody & gt; {% Endfor%} & lt; / Table & gt;
Is such a thing possible?
{{permit.getExpirationdate () | Date ('Ym-D') - "Now" | Date ('wim-d')}}
The first solution (Recommended ) "Compare with the current library:
You can use
in the toggle: it compares to the current date:
# {{Time_diff (permit.expirationDate)}}
This compares to another date:
The second solution "Do it yourself": Make def by php function: and make it available through one or the direct accessory in the unit. {# returns something like "3 minutes ago"
$ calcFrom = permit.getExpirationdate () $ now = new \ date time ('now'); $ now-> intersection ($ CalcFrom) -> Format ("% a")
The hope of this help
Comments
Post a Comment