I am trying to create a view of the expiry date and am choosing time hence - it shows something like 4 weeks and 1 day, I want it to show in days instead i.e. 29 days. I have tried using the custom formatter field that shows when time hence is chosen but it doesnt change the format.

Any ideas how to get it to show total days instead of weeks and days?

Comments

jeremymcminn’s picture

Still trying to get around this issue - cant seem to find anything on here

blueblot’s picture

Hi

have you found a solution yet?
I'm also interested in a possible solution.

Blueblot

jeremymcminn’s picture

Nothing unfortunately BlueBlot, thought this would be fairly simple with the Views GUI, but its not. I'm sure if my PHP knowledge wasnt so basic I'd be able to create some function for template.php but no idea where to start.

jeremymcminn’s picture

blueblot’s picture

hi

I solved this by changing date_time_ago.

function mytheme_date_time_ago($variables) {
  $start_date = $variables['start_date'];
  $end_date = $variables['end_date'];
  $interval = !empty($variables['interval']) ? $variables['interval'] : 2;
  $display = isset($variables['interval_display']) ? $variables['interval_display'] : 'time ago';

  // If no date is sent, then return nothing.
  if (empty($start_date) || empty($end_date)) {
    return;
  }

  // Time to compare dates to.
  $now = date_format(date_now(), DATE_FORMAT_UNIX);
  $start = date_format($start_date, DATE_FORMAT_UNIX);

  // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
  $time_diff = $start - $now;
  
  $time_diff = ceil($time_diff/86400);

  // Uses the same options used by Views format_interval.
  switch ($display) {
    case 'raw time ago':
      return format_interval($time_diff, $interval);
    case 'time ago':
      return t('%time ago', array('%time' => format_interval($time_diff, $interval)));
    
    
 //changed this because I only need this one     
   case 'raw time hence':
      return $time_diff;
             
    
    case 'time hence':
      return t('%time hence', array('%time' => format_interval(-$time_diff, $interval)));
   case 'raw time span':
      return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
    case 'inverse time span':
      return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
    case 'time span':
      return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), $interval)));
  }
}

In this situation this works for me.

Blueblot

rcodina’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Module won't support this. Use the suggestion on comment #5. Thanks!