# How to change topic date after import

**URL:** https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565
**Category:** Migration
**Tags:** rest-api, rails-console
**Created:** [January 22, 2024, 9:32pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565 "2024-01-22T21:32:18Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 22, 2024, 9:32pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/1 "2024-01-22T21:32:19Z")

</div>

I imported all my content, but I want the topic date of each new topic to change as if it was posted from today’s date, there is no additional posts per topic

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [January 22, 2024, 10:08pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/2 "2024-01-22T22:08:27Z")

</div>

It’s “Change Timestamp” in the topic wrench menu:

 ![Screenshot 2024-01-22 at 2.03.59 PM](https://global.discourse-cdn.com/meta/original/4X/0/7/5/07502dc302b9c0fb911f90ba9126550410bac8e8.png)

The dialog that pops up explains:

> Please select the new timestamp of the topic. Posts in the topic will be updated to have the same time difference.

For what it’s worth, I was using the [API](https://docs.discourse.org/#tag/Posts/operation/createTopicPostPM) and didn’t remember to set `created_at` to the actual post date.

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 22, 2024, 10:17pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/3 "2024-01-22T22:17:19Z")

</div>

Yeahhh I need to do this for 3,000+ posts though

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [January 22, 2024, 10:21pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/4 "2024-01-22T22:21:51Z")

</div>

Sounds like a job for the API: [updateTopicTimestamp](https://docs.discourse.org/#tag/Topics/operation/updateTopicTimestamp).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [January 23, 2024, 12:46am UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/5 "2024-01-23T00:46:57Z")

</div>

You can do it in rails. I think there might be an example somewhere if you search. Here’s a start.

`Topic.update_all(created_at: Time.now()`

But I would do some testing. Like, you’ll also want to update the posts?

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 28, 2024, 12:18am UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/6 "2024-01-28T00:18:12Z")

</div>

There is no posts, only 1 topic/opening post in that topic, would the command you gave work out of the box?

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [January 28, 2024, 10:02pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/7 "2024-01-28T22:02:54Z")

</div>

The dialog box for changing the topic timestamp says:

> Please select the new timestamp of the topic. Posts in the topic will be updated to have the same time difference.

If you change the date on the topic, it automatically fixes all the replies to be correct relative to the new date. So if a topic was originally dated on Jan. 1 and a reply on Jan. 5, changing the topic date to Jan. 2 will also update the reply to Jan. 6. Easy!

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 29, 2024, 7:51am UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/8 "2024-01-29T07:51:12Z")

</div>

> [@Ventrilo](#):
>
> Yeahhh I need to do this for 3,000+ posts though

Out of curiosity, why would you want all 3000+ topics to have the same date?

But, curiosity aside, you should be able to do this with the API or the rails console, if you’re comfortable using it (it’s good practice to take a backup first, just in case).

There’s some info about how to get the relevant API for things in this topic - [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576)

And there are a few examples of different rails techniques in [Administrative Bulk Operations](https://meta.discourse.org/t/administrative-bulk-operations/118349) that you could use to build what you need (or give you some idea of what to Search for).

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [February 8, 2024, 11:06pm UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/10 "2024-02-08T23:06:00Z")

</div>

Just bumping this still need additional support please

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [February 9, 2024, 12:51am UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/11 "2024-02-09T00:51:00Z")

</div>

Tried this, it doesn’t seem to make any changes but also gets no errors

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [February 9, 2024, 1:13am UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/12 "2024-02-09T01:13:01Z")

</div>

To follow Jon’s suggestion, this is the Rails console version.

```plaintext
cd /var/discourse
./launcher enter app
rails c

```

Then, for a specific topic:

```ruby
TopicTimestampChanger.new(topic: Topic.with_deleted.find(TOPIC_ID), timestamp: Time.now()).change!

```

For all topics without conditions:

```ruby
Topic.find_each do |topic| 
	TopicTimestampChanger.new(topic: topic, timestamp: Time.now()).change!  
end

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 9, 2024, 1:13am UTC](https://meta.discourse.org/t/how-to-change-topic-date-after-import/292565/13 "2024-02-09T01:13:31Z")

</div>

You might also want to change `updated_at`.
