
It is common to wish to remove the time of day shown in the node “submitted” line. In Drupal 5, there were no less than three ways to achieve this, and I will present these when I'm done covering date formatting for Drupal 6. Drupal 6 allows you to modify the different formats for dates in the Administration area of your site, these different formats being small, medium and large — yep, just like pizza, oh... my... god... You could do the same in Drupal 5. However, you then had to pick among a finite list of options. In Drupal 6, you can create an nth option, if you like none of the options presented to you.
It is the medium-size date format that's used to format the submitted line in nodes, as shown in lines 2449-2460 of modules/node/node.module:
/** * Format the "Submitted by username on date/time" for each node * * @ingroup themeable */ function theme_node_submitted($node) { return t('Submitted by !username on @datetime', array( '!username' => theme('username', $node), '@datetime' => format_date($node->created), )); }
In Drupal 6, the signature of the Drupal function format_date() is:
format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)
When the 2nd parameter is not set, 'medium' is used to format the date, and the function theme_node_submitted() is not setting that 2nd parameter when calling format_date().
To modify the medium-size format for dates, head over to the page admin/settings/date-time of your Drupal site. Under Formatting, in the drop-down list of options for “Medium date format:”, you will find a “Custom format” option. Select it. There was no such option in Drupal 5. Note that in Drupal 6 — just like in Drupal 5 — all the preset options still show time of day for the medium-size date.

Look for the preview of the current date in the text below the field on the right, where it says: This format is currently set to display as...
(Take note also that a link to the PHP manual is provided to you, to show you how to format dates in PHP.)

If all you want to do is remove the time of day from your current default, get rid of the - H:i part. Then do a Save configuration.

Now if you look at any node on your site, you will see that the change has taken effect immediately: no more time of day.

If you do not see the change, it can mean either of these two things: your theme is overriding the function theme_node_submitted(), or, the function format_date() is called within your node template file, in your theme, with some custom format, to display the date.
In Drupal 5, there were at least three ways of going about changing your date format.
Use template.php (http://drupal.org/node/209793#comment-697884) to modify the variable $submitted. Like so:
function _phptemplate_variables($hook, $vars) { switch($hook) { case 'node' : $vars['submitted'] = t('Submitted by !username on @date', array( '!username' => $vars['name'], '@date' => format_date($vars['node']->created, 'custom', 'l, j M Y'), )); break; } return $vars; }
Modify your site's settings.php file (http://drupal.org/node/134990#comment-221129) — to change your system's default medium format. Thank you, Mooffie. So you un-comment the $conf array and add one line to it, like so:
$conf = array( # 'site_name' => 'My Drupal site', # 'theme_default' => 'minnelli', # 'anonymous' => 'Visitor', 'date_format_medium' => 'D, m/d/Y', );
Modify node.tpl.php (http://drupal.org/node/134990#comment-221973) — instead of printing $submitted, you print $node->created formatted. Like so, for example:
print format_date($node->created, 'custom', 'l, j M Y');
Comments
Awesome! I was googling on
Awesome! I was googling on how to modify the submitted by thing, thanks for pointing it out, i did not know it could be customized that easy!
Thank you.
Thanks for the excellent
Thanks for the excellent post, like other people I've found this to be a blood diamonds (surprisingly) straightforward solution
hello
This is very helpful thank you...
Time ago
First of all thanks for the great tutorials Caroline it helps a lot.
may want to know how to format the date so it can show as time ago i used to do it with a module in Drupal 5 but it's not ported to D6 so if it's possible to show me thanks in advance
Many ways to do this in Drupal 6
One of them involves modifying the variable “submitted” that's passed to your node template in template.php, like so:
Not tested. Yet.
The “time ago” function in Drupal is documented here.
this code worked for me.
this code worked for me. thank you =)
Will give it a try tonight
Will give it a try tonight and see if it works thanks Caroline ;)
Thanks for the excellent
Thanks for the excellent post, like other people I've found this to be a (surprisingly) straightforward solution.
Thanks a LOT
I've been looking to do this for a LONG time - tried drupal user forums with no luck. Again, thank you!
Radu, you're very welcome!
:)
oyunlar1
very helpful thanks..
thanks
Omg, I find it!:)
Thanks very much, as Radu I've been seeking it a lot....!
How did you theme your node header?
Hey,
Great tips on your site! Question: How did you theme the teaser node on your home page to display the month and date below it, then the title and author? It's very elegant. Thanks!
Hi Pharoz
By editing node.tpl.php. The rest of it is CSS.
Well, it is very easy to
Well, it is very easy to remove it in drupal 6.0 for someone like me who is not a web developer. Although i guess my programmer would find it easy in both versions. I never actually bother to remove it but i guess it does not really required the time of the day when the user is posting comment.
I've been reading a few
I've been reading a few posts and really and enjoy your writing. I'm just starting up my own blog and only hope that I can write as well and provide the reader so significantly insight.
Love It!
I'm so grateful for someone that can provide a good description with screencaps to illustrate. I dunno why others don't do this. It makes learning this stuff a lot easier.
Thanks for this. I am very
Thanks for this. I am very beginner in drupal and learning something each day. I do not have any problems with time showing in the node but still i guess i may need it as i progress in drupal for better user experience.
Well, it is very easy to
Well, it is very easy to remove it in drupal 6.0 for someone like me who is not a web developer. Although i guess my programmer would find it easy in both versions. I never actually bother to remove it but i guess it does not really required the time of the day when the user is posting comment.
Post new comment