Generally a node displays the following information:
Submitted by Dummy on Fri, 01/27/2007 - 01:15

I would like to remove hour:minute part only, ie, 01:15 and show
Submitted by Dummy on Fri, 01/27/2007

I have searched this site. There is a lot of information about hiding author name and/or date. But I could not find how to hide hour/minute part of timestamp only.

I can create a node template file and print $date. But is shows date and time. I do not know whether variables like $hours and $minutes exist.

I do not know how to split/format $date into date, hours and minutes. Drupal API gives code for formatting date. But I do not understand it as I do not know PHP. I will be grateful if someone can give me the actual code and tell me where to put it.

Thanks to all.

Comments

sumeet.pareek’s picture

what is the version of drupal that you are using. In Drupal 6.x you can go to the 'date and time' settings page and use any of the format options that are present at http://in.php.net/date to customize how date and time should appear on your site at different places.

You can see the preview of how date and time would appear as you set the format rules :)

DrupalDummy-1’s picture

I am using 5.x.
Thanks.

sumeet.pareek’s picture

In case you are using D5 all you need to do is edit $vars['submitted'] in the template.php file of the theme that you are using. This has to be done in a function that looks like yourthemename_preprocess_node(&$vars). If this function is not already there you can create it and then make the changes. In the function body you can use format_date function that is provided by the drupal api and the creation time of the node to show the date in a format of your choice.

Here is an example that might help:


function sometheme_preprocess_node(&$vars) { 
  // change the submitted variable
  if($vars['submitted']) {
    $vars['submitted'] =  t('!a on @b',
                     array('!a' => theme('username', $vars['node']),
                     '@b' => format_date($vars['changed'],'custom','M d, Y')));
  }
}
DrupalDummy-1’s picture

Thank you. But the code did not work for me.
I added the code in template.php (I ma using Drupal 5.10)

function mythemename_preprocess_node(&$vars) {
// change the submitted variable
if($vars['submitted']) {
$vars['submitted'] = t('!a on @b',
array('!a' => theme('username', $vars['node']),
'@b' => format_date($vars['changed'],'custom','M d, Y')));
}
}

Then I tried

function phptemplate_preprocess_node(&$vars) {
// change the submitted variable
if($vars['submitted']) {
$vars['submitted'] = t('!a on @b',
array('!a' => theme('username', $vars['node']),
'@b' => format_date($vars['changed'],'custom','M d, Y')));
}
}

That too did not work.

Thanks again.

sl_hemanth’s picture

hi friend,

U know where u r printing the date.In that place print this

print substr(format_date($node->changed),0,-8);

instead of print $node->changed;

use substring function to split the minute.

regards,
hemanth

DrupalDummy-1’s picture

Hi Hemnath,

Thank you for your help. You solved my problem.

Thanks again.

paskainos’s picture

It's been a LONG time since you asked, and I assume you've already figured it out. But in the interest of helping others (too?) - the answer is remarkably simple. Too simple, in fact which is probably exactly why it's so easily overlooked. Here's how to customize your date / time stamp to your heart's content (FYI: This is a 6.x example):

  • Navigate to your site's 'Date and time Add Format' page - admin/settings/date-time/formats/add
  • Right-click on the 'PHP Manual' link and open it in another tab (or window) for reference - http://php.net/manual/function.date.php
  • Simply enter the characters you desire - WITHOUT the code markup, since Drupal takes care of that for you
  • That's it, you're done. Now just sit back and admire your handy work.

Some might still be scratching their heads a bit. Here's some clarification:

When referring to the PHP Manual, you'll undoubtedly observe the code markup of what you're after (i.e., something like: echo date('l jS \of F Y h:i:s A');). If you attempt to 'cut-n-paste' this snippet and add it as your desired format, you'll quickly discover it results in date / time vomit (i.e., something like: America/Los_Angeles2009-09-04T20:30:02-07:0008o 04pm30America/Los_Angeles('Friday 4th of September 2009 08:30:02 PM');). To fix this problem, enter ONLY the characters you need to produce the desired date / time format, and let Drupal take care of the heavy lifting for you. Here are a few examples you might even decide to use, based on the question:

  • m/d/y will produce: 09/04/09
  • D, M j, Y will produce: Fri, Sep 4, 2009
  • D, M d, Y will produce: Fri, Sep 04, 2009
  • l, F d, Y will produce: Friday, September 04, 2009

Better late than never. Hope that helps (someone).