Skip to content

Instantly share code, notes, and snippets.

@bwente
Created August 30, 2018 17:09
Show Gist options
  • Save bwente/75cacfad980e52eb2f0b3077678ddc17 to your computer and use it in GitHub Desktop.
Save bwente/75cacfad980e52eb2f0b3077678ddc17 to your computer and use it in GitHub Desktop.
MODX output filter to convert months to years
<?php
$years = floor($input/12);
$months = $input%12;
$yearsDisplay = $years.($years > 1 ? ' years' : ' year');
if($years == 0) {
$yearsDisplay = '';
}
$monthsDisplay = $months.($months > 1 ? ' months' : ' month');
if($months == 0) {
$monthsDisplay = '';
}
$output = $yearsDisplay . ($years > 0 && $months > 0 ? ', ' : ' ') . $monthsDisplay;
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment