Skip to content
Back to skills

Date Fns

ASecurity

Modern JavaScript date utility library with modular, tree-shakeable functions for formatting, parsing, comparison, and manipulation

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added October 26, 2026
developmentjavascripttypescriptgojavareactnodenodejsapifrontend

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 26, 2026

npx -y skills add nhan03bit/ultrathink --skill date-fns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Date Fns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Date Fns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nhan03bit-date-fns/badge)](https://www.skillsdirectory.com/skills/nhan03bit-date-fns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: date-fns
description: Modern JavaScript date utility library with modular, tree-shakeable functions for formatting, parsing, comparison, and manipulation
layer: domain
category: utility
triggers:
  - "date-fns"
  - "date formatting"
  - "date parsing"
  - "date comparison"
  - "date manipulation"
  - "formatDistance"
  - "parseISO"
inputs:
  - "Date formatting or display requirements"
  - "Date arithmetic or comparison logic"
  - "Timezone handling needs"
outputs:
  - "Tree-shakeable date utility implementations"
  - "Locale-aware date formatting"
  - "Timezone-safe date operations"
linksTo:
  - typescript-frontend
  - react
  - nodejs
linkedFrom:
  - forms
  - i18n
riskLevel: low
memoryReadPolicy: none
memoryWritePolicy: none
sideEffects: []
---

# date-fns

## Overview

Modern JavaScript date utility library. Each function is a standalone module — import only what you use for minimal bundle size. Works with native `Date` objects (no wrapper types).

## When to Use

- Formatting dates for display (relative time, localized strings, durations)
- Parsing date strings from APIs or user input
- Comparing or sorting dates, checking ranges
- Date arithmetic (add/subtract days, find start/end of periods)
- Timezone conversions (via `date-fns-tz`)

## Key Patterns

### Formatting

```typescript
import { format, formatDistance, formatRelative, formatDuration, intervalToDuration } from 'date-fns';

format(new Date(), 'yyyy-MM-dd HH:mm');           // "2026-03-10 14:30"
formatDistance(subDays(new Date(), 3), new Date()); // "3 days ago" (with { addSuffix: true })
formatRelative(subDays(new Date(), 1), new Date()); // "yesterday at 2:30 PM"
formatDuration(intervalToDuration({ start: 0, end: 90000000 })); // "1 day 1 hour"
```

### Parsing

```typescript
import { parse, parseISO } from 'date-fns';

parseISO('2026-03-10T14:30:00Z');                   // Date from ISO string
parse('10/03/2026', 'dd/MM/yyyy', new Date());      // Date from custom format
```

### Comparison

```typescript
import { isBefore, isAfter, isWithinInterval, differenceInDays } from 'date-fns';

isBefore(dateA, dateB);
isWithinInterval(date, { start, end });
differenceInDays(new Date(2026, 2, 10), new Date(2026, 1, 1)); // 37
```

### Manipulation

```typescript
import { add, sub, set, startOfMonth, endOfWeek } from 'date-fns';

add(new Date(), { days: 7, hours: 3 });
startOfMonth(new Date());  // First day of current month, 00:00:00
endOfWeek(new Date(), { weekStartsOn: 1 }); // Sunday end (Monday-start week)
```

### Locale Support

```typescript
import { format } from 'date-fns';
import { ja } from 'date-fns/locale'; // Import locales individually for tree-shaking

format(new Date(), 'PPP', { locale: ja }); // "2026年3月10日"
```

### Intervals and Ranges

```typescript
import { eachDayOfInterval, isWithinInterval } from 'date-fns';

eachDayOfInterval({ start: new Date(2026, 2, 1), end: new Date(2026, 2, 7) }); // Date[]
```

### UTC / Timezone Helpers (date-fns-tz)

```typescript
import { zonedTimeToUtc, utcToZonedTime, format } from 'date-fns-tz';

const utc = zonedTimeToUtc('2026-03-10 09:00', 'Asia/Tokyo');
const zoned = utcToZonedTime(utc, 'America/New_York');
format(zoned, 'yyyy-MM-dd HH:mm zzz', { timeZone: 'America/New_York' });
```

### TypeScript Types

All functions accept `Date | number` for flexibility. Use `Interval` type for range objects.

## Anti-Patterns

| Anti-Pattern | Fix |
|---|---|
| Importing entire library (`import * as dateFns`) | Import individual functions |
| Using `new Date(string)` for parsing | Use `parseISO` or `parse` with explicit format |
| Mutating dates directly | date-fns returns new Date instances (immutable) |
| Bundling all locales | Import only needed locales: `date-fns/locale/ja` |
| Ignoring timezone when comparing server/client dates | Use `date-fns-tz` for timezone-aware operations |

## Related Skills

- **typescript-frontend** — Type-safe date handling in UI components
- **react** — Date formatting in components, memo-friendly pure functions
- **nodejs** — Server-side date operations, API response formatting

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.