useDate - Admin Components

Note: This hook is available since Medusa v2.21.0.

The useDate hook formats dates using the locale of the Medusa Admin's active language. The Medusa Admin uses it to render dates in tables, detail pages, and timelines.

Code
import { useDate } from "@medusajs/dashboard/hooks"

Example#

Use the hook's functions to format a date as an absolute or a relative date:

Code
1import { useDate } from "@medusajs/dashboard/hooks"2import { Text } from "@medusajs/ui"3
4const OrderDate = ({ order }) => {5  const { getFullDate, getRelativeDate } = useDate()6
7  return (8    <div>9      <Text>10        {getFullDate({11          date: order.created_at,12          includeTime: true,13        })}14      </Text>15      <Text>{getRelativeDate(order.created_at)}</Text>16    </div>17  )18}

getFullDate returns a formatted date, such as Apr 29, 2025, and getRelativeDate returns a distance from the current time, such as 3 days ago.


Returns#

Loading...
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵