4

How can I change the date format in my comments?

Right now it looks like this:

Sat, 09/01/2012 - 12:00

I want it to look like this:

Saturday, September 1, 2012

I was able to achieve this in page.tpl.php in a section where I just display the date, but have no idea where to do this so it works for my comments too.

6

If you want to do it sitewide, you can edit the definitions at admin/config/regional/date-time/formats

You can also add your own formats there, and then use them in format_date() similar to what @Epok outlined.

  • This is the correct answer. There is no need to change the theme, when there is a global setting. – kiamlaluno Sep 2 '12 at 18:03
5

When you watch your comment.tpl.php you see that you can override some variables with template_preprocess_comment()

I don't know if it's the best way but it works fine for me. You have to put this function in template.php

function mytheme_preprocess_comment(&$variables){
  $variables['created'] = date('l, F d, Y', $variables['elements']['#comment']->created);
  $variables['changed'] = date('l, F d, Y', $variables['elements']['#comment']->created);
}

comments date There is a post about this on Drupal.org

2

You can also use format_date() function: format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)

Please note UNIX timestamp is timezone blind.

function YOURTHEME_preprocess_comment(&$variables) {      
  $variables['created'] = format_date($variables['elements']['#comment']->created, 'custom', 'l, j F Y h:i A');
}

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.