Update date when editing nodes

dreadstar's picture

Pardon the basic question but I've been stumped for hours on a seemingly easy problem.

I noticed that when a user (e.g. administrator) edits an existing node (not creating a new post or comment), the date/time stamp does not get updated. It retains the old stamp when the post was originally created. How do I make drupal automatically update the date/time stamp when someone edits a node/comment?

Please note that I want only the date/time stamp to update itself. I do not need to retain revision histories of changes. The reason for this is I noticed that my views pages are not showing when someone updates a post. Not the fault of views because I found out that after a user modifies a node, the date does not get updated hence views thinks its still an old post.

Any help in the right direction is greatly appreciated. TIA.

Comments

When I want node date/time

borrico1965's picture

When I want node date/time stamp to reflect the time-date of update, I change it manually. Perhaps there are modules at www.drupal.org that will do that automatically; I have not searched yet. I see no reason to add a module doing just that; it might affect site's performance.
I do it usually when I post my client's org news-articles to reflect the hard-copy-published-date of the news-articles. Sometimes, it is retroactive because the online version of the news-article was posted later than the publication of the news-article.
That's my two cents worth take on this issue. I hope this helps provide perspective. Best regards,

You might want to use Node:

funchum's picture

You might want to use Node: Updated date on your views sort criteria, if not check out Rules module

check this out

I have no Idea what this life is all about....

@borrico1965 Yes I can do

dreadstar's picture

@borrico1965
Yes I can do manual but Id like it done automatically.

@funchum
That wont work since the node's date is not updated in the first place during revision. Its not a views issue but a drupal core.

@edgar_estor
Yup! Thats almost identical to my problem. Instead of publish/unpublish .... my issue is on creation/revision .... but then I guess the solution would be similar. Unfortunately I am not capable of making my own module as the article mentions so I am still looking for a simple solution out there.

can you please elaborate more

jhayzhon's picture

can you please elaborate more about what you want to accomplish? I don't know but it seems like it is a problem with your views configuration.

@jhayzhon Take for example if

dreadstar's picture

@jhayzhon

Take for example if you created a story node on Jan 11 and edited (the original post not adding a comment) it on Feb 25, after it is saved, the default posted date is still on Jan 11, not the updated Feb 25. If the post was edited again for a second time on Sept 25 and saved, the posted date would still be the created date on Jan 11, not the latest updated revision on Sept 25.

In views, if I set to show story nodes for the last 3 months(shows months july, aug and sept), it would not show this node. Why? Because the date stamp is still on Jan 11.

I hope that illustrates clearer my problem and why I'm sure its not an issue with views.

Well I think the default

jhayzhon's picture

Well I think the default posted date should never be set to auto date for some reasons.

I think my workaround would be creating a CCK Date field with Date popup and add it in my content type so that I can easily change the date,
Then filter and sort it with the CCK date field that I created.

You can try using "changed"

iamrasec's picture

You can try using "changed" value instead of "created" on node table. I believe its labeled as "Node: Updated/commented date" on views.

brontoc is right. After

jhayzhon's picture

brontoc is right. After checking it on my Drupal 7 views, there is a "Content: Update date" on filter that you can use, set it's operator to show only post greater than "-30 days". I haven't checked it on Drupal 6 yet but I really believe it is just a Views configuration problem.

Bad me. I forgot to mention

dreadstar's picture

Bad me. I forgot to mention that I am using Drupal 6.xx and the filter has been set to "Node: Updated/commented date" ever since. I know its not a views problem because; as earlier mentioned by borrico1965, I can manually force the node date to update and it will show up as expected in views.

I dont think there is anything views can do if drupal retains the date stamp as creation date rather than revision date.

I would switch your filter

cmcintosh's picture

I would switch your filter from the creation date to the posted date, or you can use the revision date. this can be done via relationships. If you actually wish to change to timestamp on the nodes and update their creation date, if drupal does not do this out of the box, just create a rule using rules to have it update the creation date.

@cmcintosh Ive tried

dreadstar's picture

@cmcintosh
Ive tried everything on views side already and with no positive results. I will explore and take a look at the rules option being mentioned. I am assuming that is a 3rd party module?

Rules is a contributed module

cmcintosh's picture

Rules is a contributed module yes, but has been a while.

so create a rule that fires whenever a node is updated,
then set an action for Custom php code,
in the php code you would want to do something like

$node->created = time();
return $node;

Returning the node will tell rules that you want it to save the updated value. Also going this way you can add conditions for you to set specific nodes you want this behavior to occur on.

Tnx cmcintosh and to everyone

dreadstar's picture

Tnx cmcintosh and to everyone for their inputs. I will take a look and study the direction of using the rules module.

Template.php

jmolinas's picture

you can use php function a node $submitted override and put it in your template.php

function phptemplate_node_submitted($node) {

  $time_unit = 86400; // number of seconds in 1 day => 24 hours * 60 minutes * 60 seconds
  $threshold = 1;

  if ($node->changed && (round(($node->changed - $node->created) / $time_unit) > $threshold)){ // difference between created and changed times > than threshold
    return t('Last updated on @changed. Originally submitted by !username on @created.', array(
      '@changed' => format_date($node->changed, 'medium'),
      '!username' => theme('username', $node),
      '@created' => format_date($node->created, 'small'),
    ));
  }
  else{
    return t('Submitted by !username on @datetime.',
      array(
        '!username' => theme('username', $node),
        '@datetime' => format_date($node->created),
      ));
  }
}

Just make sure that you print your $submitted variable in your node template usually node.tpl.php in your theme

Philippines

Group organizers

Group categories

Post category

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week