Registry / data / dayjs
library1.11.20jsnpmunverified

Day.js is a minimalist JavaScript library providing a Moment.js-compatible API for parsing, validating, manipulating, and displaying dates and times. At only 2KB, it offers immutability, chainable methods, and extensive internationalization and plugin support. The current stable version is 1.11.20, and the library is actively maintained with frequent bug fix releases.

npm install dayjs
INSTALL
IMPORT
SIG · DAYJS
D
dayjs
datajavascriptv1.11.20
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dayjs
import dayjs from 'dayjs'
const dayjs = require('dayjs')
For ESM environments, use default import. CJS also supported.

Initializes a Day.js instance for the current date, then manipulates it by setting the year, adding a day, moving to the start of the month, and finally formats it into a specific string.

import dayjs from 'dayjs'; const formattedDate = dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); console.log(formattedDate); // Example output: '2018-01-02 00:00:00'
Debug
Known issues
gotchaMany common date manipulation and query functions (e.g., `isBetween`, `utc`, `duration`, `advancedFormat`) are not included in the core library. They must be explicitly imported and extended as plugins.
fix
Import the required plugin and extend Day.js: `import isBetween from 'dayjs/plugin/isBetween'; dayjs.extend(isBetween);`
affects: >=1.0.0
gotchaDay.js only includes the `en` locale by default. To use other locales, you must import them separately and then activate them globally or per instance.
fix
Import the locale: `import 'dayjs/locale/es';` then activate: `dayjs.locale('es');`
affects: >=1.0.0
gotchaDay.js instances are immutable. Methods like `add()`, `subtract()`, `set()`, `startOf()`, `endOf()` return a *new* Day.js instance rather than modifying the original. Assign the result to a new variable or chain methods.
fix
Store the result of manipulation: `const newDay = originalDay.add(1, 'day');`
affects: >=1.0.0
gotchaThe `diff()` method returns an integer difference by default. To get a floating-point number for the difference, you must pass `true` as the third argument.
fix
Use `dayjsA.diff(dayjsB, 'month', true)` for fractional differences.
affects: >=1.0.0
gotchaDay.js parsing is not as strict as some other libraries. For explicit and strict parsing of specific date formats, the `CustomParseFormat` plugin is often required.
fix
Import and use the `CustomParseFormat` plugin for precise parsing: `import customParseFormat from 'dayjs/plugin/customParseFormat'; dayjs.extend(customParseFormat); dayjs('12-25-1995', 'MM-DD-YYYY');`
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: dayjs is not defined
Attempting to use `dayjs` without importing it first.
fix
Add `import dayjs from 'dayjs';` at the top of your file.
TypeError: dayjs(...).isBetween is not a function
Attempting to use a plugin-provided method (like `isBetween`, `utc`, `duration`) without importing and extending its respective plugin.
fix
Import the specific plugin and extend Day.js with it: `import isBetween from 'dayjs/plugin/isBetween'; dayjs.extend(isBetween);`
Invalid Date
Day.js could not parse the provided date string into a valid date object, especially for non-standard formats.
fix
Ensure the date string is in a standard format (ISO 8601, JavaScript Date string), or use the `CustomParseFormat` plugin for specific formats: `dayjs.extend(customParseFormat); dayjs('25/12/1995', 'DD/MM/YYYY');`
dayjs is not a function
Incorrectly importing Day.js (e.g., `import { dayjs } from 'dayjs'` instead of `import dayjs from 'dayjs'`).
fix
Ensure you are using the default import for the main Day.js function: `import dayjs from 'dayjs';`
Locale not applying to dates
The desired locale was imported but not activated globally or for the specific Day.js instance.
fix
After importing the locale file (e.g., `import 'dayjs/locale/fr';`), activate it using `dayjs.locale('fr');` for global effect or `.locale('fr')` on an instance for local effect.
Upgrade
Version history
1.11.20latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
dayjs — npm install dayjs · libregistry