I am trying to figure out how to display the 'changed date' in nodes instead of create date. In my situation because some documents (node types page or story) continue to evolve. So the viewer can see when that content was last worked on it would be great to have that displayed instead of the obsoleted create date.

I noticed in the database there is a 'changed' field and node.module makes a few references to it. I suppose that reflects the system time of the moment when 'submit' is pressed.

In theme.inc there are/were also a few but they are all commented out.

Lastly, the online help text for node also refers to a 'Changed' field, but I fail to see that when editing a node.

I noticed a few threads regarding RSS feeds where people preferred to use the create date. But could not get any hint for my situation.

Am I missing something? Can it not be done (anymore)? Bug or feature?

Thanks for further pointers

Comments

pears447’s picture

I ran across this question on the day it was first posted, because I was wondering exactly the same thing. I have a website where I'd like to be able to easily say "This page last modified on [date]." It seems so odd that the created date is the only date I can access through PHPTemplate in my node.tpl.php file. I'd appreciate any help or ideas you have. Thanks!

styro’s picture

http://drupal.org/node/16383

Just an idea worth trying - I'm not exactly sure it will do what you need though.

MartinA-1’s picture

Looks impressive - but for a non-fluent coder... hm.

So I guess this would be a feature request.

pears447’s picture

While styro's suggestion looks helpful, I don't know enough PHP to work with it. Any specific ideas as to how to make PHPTemplate pass the changed date (if such a value is even stored at all) as a variable?

I would think that this would be a pretty common issue -- lots of sites have a "Last Modified" date. It would be great if this was incorporated as a feature.

hellata’s picture

Look at the node.tpl.php file under themes/your-theme.

Replace

<span class="submitted"><?php print $submitted?></span>

With

<span class="submitted">
  <?php 
        print "Modified by ".format_name($node)." on ".format_date($node->changed); 
  ?>
</span>
pears447’s picture

Thanks so much. This works famously -- just the sort of thing I was looking for. I had to flush the cache before it took effect on all pages, but once I did that, it worked great. A nice solution to this problem.

funkioto’s picture

This works perfectly.
All I changed was the $node->created to $node->changed
thanks!
yay for Drupal :)

  <?php if ($submitted): ?>
    <div class="info"><?php print format_name($node) . ' â ' . str_replace('-', ' â ', format_date($node->changed)) ?></div>
  <?php endif; ?>
jferjan’s picture

I just replaced
<span class="submitted"><?php print $submitted?></span>

with
<span class="submitted"><?php print format_date($node->changed)?></span>

www.gaia-plus.si
www.ferjan.net

thelorax’s picture

Since all of the examples so far have been for those using phptemplate and not the default xtemplate engine, I thought I'd offer up instructions on how to do this with a standard Drupal 4.6 site.

Unfortunately the xtemplate theme engine does not expose the changed date by default, so first you're going to need to edit the xtemplate.engine file (/themes/engines/xtemplate/xtemplate.engine) At about line 43 you should see something like this:

"submitted" => theme_get_setting("toggle_node_info_$node->type") ?
                         t("Submitted by %a on %b.",
                           array("%a" => format_name($node),
                            "%b" => format_date($node->created))) : '',

You can either add in another variable "changed" by creating a new line like this:

"changed" => theme_get_setting("toggle_node_info_$node->type") ?
                         t("Last updated %a.",
                           array("%a" => format_date($node->changed))) : '',

or you can simply change the "submitted" line so that it really is the changed date like this:

"submitted" => theme_get_setting("toggle_node_info_$node->type") ?
                         t("Written by %a last updated on %b.",
                           array("%a" => format_name($node),
                            "%b" => format_date($node->changed))) : '',

Now that we have a new template variable called "changed" we can refer to it within the xtemplate.xtmpl file of our theme by using the {changed} tag - I have something like this:

<!-- BEGIN: node -->
  <div class="node {sticky}">
    <!-- BEGIN: picture -->
    {picture}
    <!-- END: picture -->
    <!-- BEGIN: title -->
    <h2 class="title"><a href="{link}">{title}</a></h2>
    <!-- END: title -->
    <span class="submitted">{submitted}</span><br />
    <span class="submitted">{changed}</span><br />
    <!-- BEGIN: taxonomy -->
    <span class="taxonomy">{taxonomy}</span>
    <!-- END: taxonomy -->
    <div class="content">{content}</div>
    <!-- BEGIN: links -->
    <div class="links">&raquo; {links}</div>
    <!-- END: links -->
  </div>
<!-- END: node -->