SOLVED: How to add timestamp to article page

I’m hoping to add a timestamp / publication time to my articles.

I would like it to appear next to the date (and then move down reading time to the next line).

The kind folks at support directed me to this page -

But that does not directly deal with what I need, which is the specific code to add pub time.

It does include the following sentence - See the Moment.js Display tokens for more options. - which seems like it would offer some clues.

But that page - Moment.js | Docs - seems to be in a completely different format from how the code in my post-meta.hbs file appears, as follows:

<div class="gh-article-meta">
            <time class="gh-article-date" datetime="{{date format="YYYY-MM-DD"}}">{{date}}</time>
        </div>

In the interest of not bothering the support folks again, I was hoping someone here might clarify: Do I need to completely change the format of all of this code if I want to add pub time? (Otherwise, idk what to make of the moment.js info.) Or is there simply some time-related code I could add to this to add pub time to what displays? If so, where can I find examples of different formatting options for that - and do I put it inside the string that includes the date, or is it separate from that?

I took a shot in the dark and tried throwing in {{time}} after date… but I didn’t get anywhere. This has all got to be spelled out somewhere but I could not find it. I’m about ready to just manually start typing in my pub time somewhere in the story…

Maybe someone who has already added timestamps can clue me in…

THANK YOU! :)

I’ve never tried it myself, but I think the portion of the moment.js page you want to be looking at is this:

You might want to try duplicating {{date format="YYYY-MM-DD"}} with something like {{date format="h-m"}}. Or {{time format="h-m"}}?. I’m guessing that if you play around with it a bit you’ll get it.

Thanks, I will do that. There’s definitely a lot of trial-and-error happening over here!

Well I underestimated the concept of “play around with it a bit.” How many hours has it been?? I really do not have a good grasp of code so I did a lot of experimenting with each element to understand what they were doing / not doing.

Here’s what ultimately produced the timestamp for me:

<time class="gh-article-date">{{date format="MMMM D, YYYY h:mm A"}}</time>

I had to get rid of the Ghost {{date}} helper and move the date format language into the output area. (Sorry, I don’t know the technical terms for the various pieces of this; I’ll have to read up.)

An even simpler solution is located in the following table, which is linked on the page Ghost pointed me toward (although a bit more specificity may have gotten me there MUCH faster but, hey, I’ve certainly learned a lot!!).

So here is the corresponding code from the table that outputs the same as the lengthier solution above.

<time class="gh-article-date">{{date format="LLL"}}</time>

I’ll also note that the Ghost page re: dates DOES include the following sentence:

If you call {{date}} without a format, it will default to a short localised format, ll .

This made no sense to me until I saw the table above and ultimately understood the context.

Here’s how it now looks on my site:

To make it perfect, I would figure out how to format all months in line with AP style and also find a way to format PM to “p.m.” in line with AP style — but that will have to wait for another day!

Thanks for your encouragement @Stromfeldt! I was truly just on the cusp of throwing in the towel but I soldiered on until the “aha” moment because of your instinct that it was extremely solvable.

I’ve never been so happy to see a timestamp in my life!

1 Like