Skip to main content

Legal Pages - Last Updated Date

Legal pages automatically display the last updated date from Sanity.

Overview​

Legal pages (Privacy Policy, Terms of Service, etc.) now display the publish date from Sanity, providing transparency about when the content was last updated.

Implementation​

The publishedAt field is fetched from the page document and displayed at the top or bottom of the legal page content.

Date Formatting​

The date is formatted based on the current locale:

  • English (en-US): "Last updated: January 15, 2024"
  • Spanish (es-ES): "Last updated: 15 de enero de 2024"
  • Romanian (ro-RO): "Last updated: 15 ianuarie 2024"
  • Fallback: "Last updated: Recently" (if no date is available)

Sanity Schema​

Ensure your page schema includes the publishedAt field:

{
name: 'publishedAt',
type: 'datetime',
title: 'Published At',
description: 'When this page was published',
options: {
dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm',
timeStep: 15
}
}
{
name: 'legalPage',
type: 'document',
title: 'Legal Page',
fields: [
{
name: 'title',
type: 'object',
fields: [
{ name: 'en', type: 'string' },
{ name: 'es', type: 'string' },
{ name: 'ro', type: 'string' }
]
},
{
name: 'slug',
type: 'slug',
options: {
source: 'title.en'
}
},
{
name: 'content',
type: 'array',
of: [{ type: 'block' }]
},
{
name: 'publishedAt',
type: 'datetime',
title: 'Published At',
description: 'When this page was published'
}
],
preview: {
select: {
title: 'title.en',
publishedAt: 'publishedAt'
}
}
}

Display Format​

English Format​

Last updated: January 15, 2024

Spanish Format​

Last updated: 15 de enero de 2024

Romanian Format​

Last updated: 15 ianuarie 2024

Fallback​

If no publishedAt date is available:

Last updated: Recently

Frontend Implementation​

The frontend automatically:

  • Fetches the publishedAt field from the page document
  • Formats the date based on the current locale
  • Displays the formatted date with appropriate styling
  • Falls back to "Recently" if no date is available

Example Component​

import { format } from 'date-fns'
import { enUS, es, ro } from 'date-fns/locale'

const locales = {
en: enUS,
es: es,
ro: ro
}

export function LegalPageDate({ publishedAt, locale = 'en' }) {
if (!publishedAt) {
return <p>Last updated: Recently</p>
}

const date = new Date(publishedAt)
const formatted = format(date, 'MMMM d, yyyy', {
locale: locales[locale]
})

return <p>Last updated: {formatted}</p>
}

Updating the Published Date​

When updating legal page content:

  1. Edit the page in Sanity Studio
  2. Update the publishedAt field to the current date/time
  3. Publish the changes
  4. The new date will automatically appear on the page

Best Practices​

  • Update publishedAt whenever significant changes are made
  • Use the actual publication date, not the current date if backdating
  • Keep dates accurate for legal compliance
  • Consider adding a changelog for major updates

Displaying the last updated date helps with:

  • Transparency: Users know when content was last reviewed
  • Compliance: Some jurisdictions require date information
  • Trust: Shows active maintenance of legal documents
  • Accountability: Clear record of when changes were made

Localization​

The date format automatically adapts to the current locale:

  • Users see dates in their language
  • Format matches regional conventions
  • Month names are properly localized
  • Date order follows locale standards

Next Steps​