1

I have changed date formats in Views and in Drupal core Date settings, but I'm still seeing wrong date format on forum (for example in node where conversation is) at class .forum-posted-on.

In template file advanced-forum.myforumtemplate.post.tpl.php:

<?php print $date ?>

How to change date format?

3

You need to alter the date through template_preprocess_node() and template_preprocess_comment() in your theme. The first preprocess is used for the forum nodes (initial forum post) and the latter for comments (replies).

Add the following code to your theme's template.php file:

function YOUR_THEME_preprocess_node(&$variables) {
  if ($variables['node']->type=='forum') {
    // Custom date.
    $variables['date'] = format_date($variables['node']->created, 'custom', 'M d Y, H:i:s');
    // Use date format provided by Drupal:
    // $variables['date'] = format_date($variables['node']->created, 'short');
  }
}

function YOUR_THEME_preprocess_comment(&$variables) {
  if ($variables['node']->type=='forum') {
    // Custom date.
    $variables['date'] = format_date($variables['node']->created, 'custom', 'M d Y, H:i:s');
    // Use date format provided by Drupal:
    // $variables['date'] = format_date($variables['node']->created, 'short');
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.