0

Using Views > fields I want to sort 'date_modify' result. The statement(code) below provides all the dates (unsorted), nicely, however Views > Sort Criteria doesn't work since it seems to only sort the date value before 'date_modify'.

Here's what I have going on: In my content type I have a field called "Condition." It's a select option field with: Good, Fair, Poor (keys are the same in lowercase). And I have a field called "Evaluation date" which is manually set to current date(not time) by user for each item. The user selects the Condition of an item and then the current date. The statement below generates the next evaluation date.

What I want to do with the resulting modified dates is sort them so that the dates in or closest to current month appears first, then by "+1 year" dates, then by "+5 years" dates. I also want it sorted by year then month but have it display as m/y:

Example - Not (this stuff):

05/24 FURNACE (Items in poor condition - Next evaluation is current month)
05/25 ROOF (Items in fair condition - Next evaluation is +1 year)
05/29 WINDOWS (Items in good condition - Next evaluation is +5 years)

In long form this says:

"The furnace(item) was evaluated today and its condition is Poor. It needs to be re-evaluated now [05/24]."

"The roof(item) was evaluated today and its condition is Fair. It needs to be re-evaluated this date [05/25]."

"The windows(item) were evaluated today and its condition is Good. They need to be re-evaluated this date [05/29]."

{% if field_condition == 'fair' %}
  {{ field_evaluation_date_1__value|date_modify("+1 year")|date("m/y") }}
{% elseif field_condition == 'good' %}
  {{ field_evaluation_date_1__value|date_modify("+5 years")|date("m/y") }}
{% elseif  field_condition == 'poor' %}
{{ field_evaluation_date_1__value|date("m/y") }}
{% endif %}

This statement is in the re-write section of Evaluation date field.

My knowledge of Twig/PHP is very minimal.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.