{"id":14526,"library":"dayjs","title":"Day.js","description":"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.","status":"active","version":"1.11.20","language":"javascript","source_language":"en","source_url":"https://github.com/iamkun/dayjs","tags":["javascript","dayjs","date","time","immutable","moment","typescript"],"install":[{"cmd":"npm install dayjs","lang":"bash","label":"npm"},{"cmd":"yarn add dayjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add dayjs","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM environments, use default import. CJS also supported.","wrong":"const dayjs = require('dayjs')","symbol":"dayjs","correct":"import dayjs from 'dayjs'"}],"quickstart":{"code":"import dayjs from 'dayjs';\n\nconst formattedDate = dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');\n\nconsole.log(formattedDate);\n// Example output: '2018-01-02 00:00:00'","lang":"typescript","description":"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."},"warnings":[{"fix":"Import the required plugin and extend Day.js: `import isBetween from 'dayjs/plugin/isBetween'; dayjs.extend(isBetween);`","message":"Many 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Import the locale: `import 'dayjs/locale/es';` then activate: `dayjs.locale('es');`","message":"Day.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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Store the result of manipulation: `const newDay = originalDay.add(1, 'day');`","message":"Day.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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `dayjsA.diff(dayjsB, 'month', true)` for fractional differences.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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');`","message":"Day.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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Add `import dayjs from 'dayjs';` at the top of your file.","cause":"Attempting to use `dayjs` without importing it first.","error":"ReferenceError: dayjs is not defined"},{"fix":"Import the specific plugin and extend Day.js with it: `import isBetween from 'dayjs/plugin/isBetween'; dayjs.extend(isBetween);`","cause":"Attempting to use a plugin-provided method (like `isBetween`, `utc`, `duration`) without importing and extending its respective plugin.","error":"TypeError: dayjs(...).isBetween is not a function"},{"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');`","cause":"Day.js could not parse the provided date string into a valid date object, especially for non-standard formats.","error":"Invalid Date"},{"fix":"Ensure you are using the default import for the main Day.js function: `import dayjs from 'dayjs';`","cause":"Incorrectly importing Day.js (e.g., `import { dayjs } from 'dayjs'` instead of `import dayjs from 'dayjs'`).","error":"dayjs is not a function"},{"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.","cause":"The desired locale was imported but not activated globally or for the specific Day.js instance.","error":"Locale not applying to dates"}],"ecosystem":"npm"}