1 ---
2 sidebar_label: "useDate"
3 ---
4
5 import { TypeList } from "docs-ui"
6
7 export const metadata = {
8 title: `useDate - Admin Components`,
9 }
10
11 # {metadata.title}
12
13 <Note>
14
15 This hook is available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0).
16
17 </Note>
18
19 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.
20
21 ```tsx
22 import { useDate } from "@medusajs/dashboard/hooks"
23 ```
24
25 ---
26
27 ## Example
28
29 Use the hook's functions to format a date as an absolute or a relative date:
30
31 ```tsx
32 import { useDate } from "@medusajs/dashboard/hooks"
33 import { Text } from "@medusajs/ui"
34
35 const OrderDate = ({ order }) => {
36 const { getFullDate, getRelativeDate } = useDate()
37
38 return (
39 <div>
40 <Text>
41 {getFullDate({
42 date: order.created_at,
43 includeTime: true,
44 })}
45 </Text>
46 <Text>{getRelativeDate(order.created_at)}</Text>
47 </div>
48 )
49 }
50 ```
51
52 `getFullDate` returns a formatted date, such as `Apr 29, 2025`, and `getRelativeDate` returns a distance from the current time, such as `3 days ago`.
53
54 ---
55
56 ## Returns
57
58 <TypeList
59 types={[
60 {
61 name: "getFullDate",
62 type: "`(params: { date: string | Date; includeTime?: boolean }) => string`",
63 description: "Formats a date in the active locale. Set `includeTime` to `true` to append the time, which is `false` by default. If the passed date is invalid, the function returns an empty string.",
64 },
65 {
66 name: "getRelativeDate",
67 type: "`(date: string | Date) => string`",
68 description: "Formats the distance between the passed date and the current time in the active locale, with a suffix such as `ago` or `in`.",
69 },
70 ]}
71 />