# Undo change timestamp

**URL:** <https://meta.discourse.org/t/undo-change-timestamp/78966>\
**Category:** Sysadmins\
**Tags:** how-to\
**Created:** [January 25, 2018, 3:18pm UTC](https://meta.discourse.org/t/undo-change-timestamp/78966 "2018-01-25T15:18:30Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)\
**Post date:** [January 25, 2018, 3:18pm UTC](https://meta.discourse.org/t/undo-change-timestamp/78966/1 "2018-01-25T15:18:30Z")

</div>

One of our mods changed the timestamp as a way to unbump a topic and I wanted to revert that change because. I wrote a rake task that does this. It’s a small thing, but why not share?

```ruby
# /var/www/discourse/lib/tasks/set_timestamp_to_last_version.rake
desc "Set timestamp of all posts in a topic to the post's last_version_at"
task "set_timestamp_to_last_version", [:topic_id] => :environment do |_, args|
  topic_id = args[:topic_id]
  if !topic_id
    puts "ERROR: Expecting rake set_timestamp_to_last_version[topic_id]"
    exit 1
  end

  Post.where(topic_id: topic_id).each do |p|
    p.created_at = p.last_version_at
    p.updated_at = p.last_version_at
    if !p.save
      puts "post save error on #{p.id}"
    end
  end

  p_first = Post.where(topic_id: topic_id).first
  p_last = Post.where(topic_id: topic_id).last

  t = Topic.where(id: topic_id).first
  t.created_at = p_first.last_version_at
  t.updated_at = p_last.last_version_at
  t.bumped_at = p_last.last_version_at
  t.last_posted_at = p_last.last_version_at
  if !t.save
    puts "post save error on #{t.id}"
  end
end

```

---

_[View the full topic](https://meta.discourse.org/t/undo-change-timestamp/78966)._
