# How to get .Page.Lastmod to display only if it's different from created .date?

**URL:** <https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024>\
**Category:** support\
**Created:** [May 26, 2024, 12:37am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024 "2024-05-26T00:37:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_Midjich](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/stefan_midjich/32/20279_2.png) [@Stefan\_Midjich](https://discourse.gohugo.io/u/Stefan_Midjich)\
**Post date:** [May 26, 2024, 12:37am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024/1 "2024-05-26T00:37:03Z")

</div>

I want to display last updated on pages that have been updated, but not others.

Here is what I got so far.

```auto
  {{- if .Lastmod -}}
  <h4 class="subtitle ml-2">
    Last updated <time datetime="{{ .Lastmod }}">{{ .Lastmod | time.Format ":date_medium" }}</time>
  </h4>
  {{- end -}}

```

I also tried if isset .Lastmod but it’s always set. I need to do some sort of comparison which I have no idea how to do in hugo templating.

---

<div class="post-metadata">

**Author:** ![Stefan\_Midjich](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/stefan_midjich/32/20279_2.png) [@Stefan\_Midjich](https://discourse.gohugo.io/u/Stefan_Midjich)\
**Post date:** [May 26, 2024, 12:38am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024/2 "2024-05-26T00:38:23Z")

</div>

I think I figured it out already.

```auto
  {{- if compare.Gt .Lastmod .Date -}}
  <h4 class="subtitle ml-2">
    Last updated <time datetime="{{ .Lastmod }}">{{ .Lastmod | time.Format ":date_medium" }}</time>
  </h4>
  {{- end -}}

```

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 26, 2024, 6:16am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024/3 "2024-05-26T06:16:27Z")

</div>

`{{ if not eq .Lastmod .Date }}` is probably more error proof, in case your `.Date` is after `.Lastmod`.

---

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [May 26, 2024, 8:57am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024/4 "2024-05-26T08:57:20Z")

</div>

> [@davidsneighbour](#):
>
> `{{ if not eq .Lastmod .Date }}`

```auto
execute of template failed at <not>: wrong number of args for not: want 1 got 3

```

👇 👇 👇 👇

```auto
{{ if not (eq .Lastmod .Date) }}

```

---

<div class="post-metadata">

**Author:** ![guangmean](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/guangmean/32/22094_2.png) [@guangmean](https://discourse.gohugo.io/u/guangmean)\
**Post date:** [May 27, 2024, 12:22am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024/5 "2024-05-27T00:22:38Z")

</div>

{{ if gt .Lastmod .Date }}

more better?

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [May 29, 2024, 12:22am UTC](https://discourse.gohugo.io/t/how-to-get-page-lastmod-to-display-only-if-its-different-from-created-date/50024/6 "2024-05-29T00:22:49Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
