UNPKG

773 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name getDate
5 * @category Day Helpers
6 * @summary Get the day of the month of the given date.
7 *
8 * @description
9 * Get the day of the month of the given date.
10 *
11 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
12 *
13 * @param date - The given date
14 *
15 * @returns The day of month
16 *
17 * @example
18 * // Which day of the month is 29 February 2012?
19 * const result = getDate(new Date(2012, 1, 29))
20 * //=> 29
21 */
22export function getDate(date) {
23 const _date = toDate(date);
24 const dayOfMonth = _date.getDate();
25 return dayOfMonth;
26}
27
28// Fallback for modularized imports:
29export default getDate;