# Accessing current date via shortcode?

**URL:** <https://zola.discourse.group/t/accessing-current-date-via-shortcode/2515>\
**Category:** Support\
**Created:** [March 13, 2025, 4:46pm UTC](https://zola.discourse.group/t/accessing-current-date-via-shortcode/2515 "2025-03-13T16:46:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jat255](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/jat255/32/1426_2.png) [@jat255](https://zola.discourse.group/u/jat255)\
**Post date:** [March 13, 2025, 4:46pm UTC](https://zola.discourse.group/t/accessing-current-date-via-shortcode/2515/1 "2025-03-13T16:46:21Z")

</div>

I have a site built using Zola (loving it, so far!) and have a “last updated” section in my footer. Currently, I’m manually updating that date, but it would be great if there was a shortcode I could use to get the current date (as of the `zola build` time). I looked through the docs, but didn’t see anything about dates and times. Did I just miss something?

Otherwise, would anyone have some tips about how to implement such a feature?

---

<div class="post-metadata">

**Author:** ![adrianboston](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/adrianboston/32/907_2.png) [@adrianboston](https://zola.discourse.group/u/adrianboston)\
**Post date:** [March 13, 2025, 8:52pm UTC](https://zola.discourse.group/t/accessing-current-date-via-shortcode/2515/2 "2025-03-13T20:52:10Z")

</div>

Do you want that updated for the entire site or one markdown page

1. A single entry (page) does have the ability for an ‘updated’ and ‘date’ field.  
[Sections and Pages | Zola](https://www.getzola.org/documentation/templates/pages-sections/)

2. In the pagination section one can sort by `date` and `updated`  
[Section | Zola](https://www.getzola.org/documentation/content/section/#sorting)  
Presumably if you use `updated` then the top page will have the most recent date.  
`Note: Any page that is missing the data it needs to be sorted will be ignored and won't be rendered. For example, if a page is missing the date variable and its section sets `sort\_by = “date”` , then that page will be ignored. The terminal will warn you if this occurs.`

3. And one can add any field to the entire site via the config.toml file by adding

> [extra]  
> updated = “”

However, Imho i do believe that date must be manually entered. and does not use the build time.

---

<div class="post-metadata">

**Author:** ![jat255](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/jat255/32/1426_2.png) [@jat255](https://zola.discourse.group/u/jat255)\
**Post date:** [March 15, 2025, 4:30pm UTC](https://zola.discourse.group/t/accessing-current-date-via-shortcode/2515/3 "2025-03-15T16:30:02Z")

</div>

Thanks for those suggestions. This feels like something that could be a useful short code, but I don’t know enough about the internals of Zola to know how to do that.

Either way, I was able to get what I needed by adding the date to the extra section metadata, and then writing a small `sed` script that will replace the date with the current one that gets run as a pre-commit hook on my repo. Thanks for the help!

Example script:

```sh
#!/bin/bash
# put this file in <repo_dir>/.git/hooks/pre-commit and make it executable
# it will be run every time you make a commit to silently update the date
# in the _index.md file at commit time (only on the main branch)

BRANCH_NAME=$( git rev-parse --abbrev-ref HEAD )
if ["$BRANCH_NAME" = "main"]; then
    echo "------------------------------------------------------------"
    echo "Pre-commit hook to update \"last updated\" date on main page"
    echo "------------------------------------------------------------"

    TODAY=$(date +%Y-%m-%d)
    echo "Original updated date in content/_index.md:"
    echo $( grep updated\ = content/_index.md )
    echo ""

    sed -i -E "s/^updated = \"[0-9]{4}-[0-9]{2}-[0-9]{2}\"$/updated = \"${TODAY}\"/" content/_index.md

    echo "Updated updated date in content/_index.md:"
    echo $( grep updated\ = content/_index.md )
    echo ""

    git add content/_index.md
fi

```

---

<div class="post-metadata">

**Author:** ![adrianboston](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/adrianboston/32/907_2.png) [@adrianboston](https://zola.discourse.group/u/adrianboston)\
**Post date:** [March 15, 2025, 11:06pm UTC](https://zola.discourse.group/t/accessing-current-date-via-shortcode/2515/4 "2025-03-15T23:06:54Z")

</div>

> [@jat255](#):
>
> Either way, I was able to get what I needed by adding the date to the extra section metadata, and then writing a small `sed` script that will replace the date with the current one that gets run as a pre-commit hook on my repo. Thanks for the help!

So this is a git commit time less than a post time - and doesn’t alter the individual posts data but section. Yeah thats cool actually. I think its good to have a site update time.

make with zola is useful. And rsync it up to aws.
