# 修改帖子日期？

**URL:** https://meta.discourse.org/t/editing-post-date/19506
**Category:** Feature
**Created:** [2014年九月1日 15:36 UTC](https://meta.discourse.org/t/editing-post-date/19506 "2014-09-01T15:36:59Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 15:36 UTC](https://meta.discourse.org/t/editing-post-date/19506/1 "2014-09-01T15:36:59Z")

</div>

Hi there,

How would I go about altering the post date on a topic or post within a topic?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2014年九月1日 15:53 UTC](https://meta.discourse.org/t/editing-post-date/19506/2 "2014-09-01T15:53:51Z")

</div>

There is no way to do this at the current time… no pun intended.

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 16:13 UTC](https://meta.discourse.org/t/editing-post-date/19506/3 "2014-09-01T16:13:31Z")

</div>

Poo ☹

Does ‘not possible’ also include from the command-line?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2014年九月1日 16:42 UTC](https://meta.discourse.org/t/editing-post-date/19506/4 "2014-09-01T16:42:17Z")

</div>

It’s probably possible via Ruby command line or direct SQL, of course. I only meant the web UI.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2014年九月1日 21:59 UTC](https://meta.discourse.org/t/editing-post-date/19506/5 "2014-09-01T21:59:43Z")

</div>

Here’s how to do it via the command line

```bash
# ssh into your server
cd /var/discourse # or /var/docker on pre-V1 install
./launcher enter app
rails c
post = Post.find_by(id: 1234)
post.created_at = DateTime.new(2001,2,3,0,0,42) # year, month, day, hour, minute, seconds 
post.save

```

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 22:23 UTC](https://meta.discourse.org/t/editing-post-date/19506/6 "2014-09-01T22:23:27Z")

</div>

Awesome! This seems to have worked, but I’m unclear on what I’m supposed to do or how to safely exit once I’ve altered the date/time.

 ![](https://global.discourse-cdn.com/meta/original/3X/7/5/75e3946c2dd6b227c2dc57b93f0e0f29d0e32d57.png) 

Looking at my test install, the date for that post hasn’t changed… I’m sure I’m missing something? Thanks for your help!

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2014年九月1日 22:27 UTC](https://meta.discourse.org/t/editing-post-date/19506/7 "2014-09-01T22:27:32Z")

</div>

CTRL + D is how you exit 😉

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [2014年九月1日 22:28 UTC](https://meta.discourse.org/t/editing-post-date/19506/8 "2014-09-01T22:28:16Z")

</div>

Or by typing `exit` or `!!!`. 😁

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 22:36 UTC](https://meta.discourse.org/t/editing-post-date/19506/9 "2014-09-01T22:36:49Z")

</div>

Hm… I manage to exit out. I was doing it properly (but wanted to ask in case I was just being a moron), but get a message saying:

> Unable to write to your history file, history not saved

![](https://global.discourse-cdn.com/meta/original/3X/9/f/9f8f3548e3854aa03326c03dc9805a412b463837.png)

Thanks again for your help and patience guys; Ruby is still pretty new to me but I’m learning to love it.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2014年九月1日 22:40 UTC](https://meta.discourse.org/t/editing-post-date/19506/10 "2014-09-01T22:40:31Z")

</div>

Yeah, that’s a different thing all together, one that you probably don’t need to worry about. It is simply telling you it didn’t save the commands you entered so when you connect later you could use `history` to see what commands you ran previously.

If you re-run rails c and type `history`, you should get a blank list. If you enter a few commands and run it again, you will see a list of the commands you have run up to that point.

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 22:42 UTC](https://meta.discourse.org/t/editing-post-date/19506/11 "2014-09-01T22:42:03Z")

</div>

Is there something else I need to do to get the changes to show up on the front-end then? The post I edited is still showing the original date. Reboot Discourse, perhaps?

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2014年九月1日 22:49 UTC](https://meta.discourse.org/t/editing-post-date/19506/12 "2014-09-01T22:49:26Z")

</div>

I’m not sure, @zogstrip does he need to rebake the post? Or clear any caches?

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 22:53 UTC](https://meta.discourse.org/t/editing-post-date/19506/13 "2014-09-01T22:53:02Z")

</div>

@zogstrip @cpradio

Disregard my last question… In looking at the output in red in those screenshots above, I don’t seem to be targeting the post I think I am… The summary text in there is coming from one of the posts that get created when making a new category.

How would I properly determine a post’s ID? This one, for example:  
[http://forum.curiouscosmos.com/t/object-floating-above-newfoundland-iceberg/37/2?u=cosmo](http://forum.curiouscosmos.com/t/object-floating-above-newfoundland-iceberg/37/2?u=cosmo)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2014年九月1日 22:58 UTC](https://meta.discourse.org/t/editing-post-date/19506/14 "2014-09-01T22:58:17Z")

</div>

Performing a view source, contains this:  
`<article class="boxed" id="post_2" data-bindattr-28="28" data-post-id="39" data-bindattr-29="29" data-user-id="1">`

Which has `data-post-id="39"`

I can’t promise that is the correct answer though…

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月1日 23:06 UTC](https://meta.discourse.org/t/editing-post-date/19506/15 "2014-09-01T23:06:38Z")

</div>

Yessir, that was it! I suppose it helps if I’m actually changing the correct post ID 😉

Thank you for all your help!

🍻

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [2014年九月1日 23:35 UTC](https://meta.discourse.org/t/editing-post-date/19506/16 "2014-09-01T23:35:53Z")

</div>

By the way, you can also find the post by the topic id and post number which are perhaps easier to read from the forum via the share link instead of inspecting source:

`Post.find_by(topic_id: 123, post_number: 45)`

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月2日 00:16 UTC](https://meta.discourse.org/t/editing-post-date/19506/17 "2014-09-02T00:16:18Z")

</div>

This is working excellently, though I do have one more question:

How do I force a refresh or update of the last “activity” on the thread listing page? If all of the dates within a thread have a date of May or June, the last activity shouldn’t say 22 minutes ago

![](https://global.discourse-cdn.com/meta/original/3X/c/4/c471c1b590c25176b9f55496da3082560cae5ae5.png)

Thanks guys 🙂

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [2014年九月2日 00:53 UTC](https://meta.discourse.org/t/editing-post-date/19506/18 "2014-09-02T00:53:47Z")

</div>

You can see how Discourse does this internally in the `PostCreator` class:

> <https://github.com/discourse/discourse/blob/v1.0.0/lib/post_creator.rb#L195-L203>

So in your case, this should do:

```ruby
t = Topic.find(123)
t.last_posted_at = t.posts.last.created_at
t.bumped_at = t.posts.last.created_at
t.save!

```

---

<div class="post-metadata">

### Author: ![Brentnauer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brentnauer/32/114845_2.png) [@Brentnauer](https://meta.discourse.org/u/Brentnauer)
#### Post date: [2014年九月2日 01:05 UTC](https://meta.discourse.org/t/editing-post-date/19506/19 "2014-09-02T01:05:22Z")

</div>

Thanks! That pointed me in the right direction.

I found that I had to also update bumped\_at and updated\_at (or whatever their proper names are, I’m not looking at the screen right now).

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2014年九月2日 17:00 UTC](https://meta.discourse.org/t/editing-post-date/19506/20 "2014-09-02T17:00:13Z")

</div>

The bumped\_at field is what is displayed & sorted by.

[下一頁](https://meta.discourse.org/t/editing-post-date/19506.md?page=2)
