Ben Borgers

How to get the last time a Gatsby site was built

If your Gatsby site pulls in data at build time, it can be helpful to show visitors when the site was last built.

This site ( was last built just now.

This component relies on a GraphQL query to fetch the build time, and then formats it using a lightweight package called tiny-relative-date.

Here is the abbreviated component (without styling):

import React from "react"
import { useStaticQuery, graphql } from "gatsby"
import relativeDate from "tiny-relative-date"

export default () => {
  const query = useStaticQuery(graphql`
    query {
      site {

  const buildTime = new Date(
  const buildTimeRelative = relativeDate(buildTime)

  return (
    <p>This site ( was last built {buildTimeRelative}.</p>

Subscribe to my biweekly newsletter with articles and tips for Gatsby.