---
title: "Date Units"
description: "DateUnit, to move a date by days, weeks, months, quarters, semesters and years, and Weekday"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-11-05"
last_update: "2026-11-05"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/core/date/date-units"
---

# Date Units

```php
use Derafu\Date\Enum\DateUnit;
use Derafu\Date\Enum\Weekday;
```

## DateUnit

`DateUnit` is an enum of the units of time. The value of each case is its one-letter code.

| Case | Code | Months |
| --- | --- | --- |
| `DAY` | `D` | |
| `WEEK` | `W` | |
| `MONTH` | `M` | 1 |
| `QUARTER` | `Q` | 3 |
| `SEMESTER` | `S` | 6 |
| `YEAR` | `Y` | 12 |

`DateUnit::fromCode('m')` gives the unit of a code in upper or lower case, and an `InvalidDateException` if there is none. `getMonths()` gives the months of the unit, or `null` for days and weeks.

## Move a date

```php
DateUnit::MONTH->add($date, 1);        // a month later
DateUnit::QUARTER->subtract($date, 2); // two quarters earlier
DateUnit::DAY->add($date, -3);         // a negative number goes the other way
```

`add($date, $steps = 1)` and `subtract($date, $steps = 1)` give a new `DateTimeImmutable`; the date that is given does not change and its time is kept.

Months, quarters, semesters and years never overflow: the day that the month of the result does not have is the last day of that month.

| Date | Move | Result |
| --- | --- | --- |
| `2024-01-31` | + 1 month | `2024-02-29` |
| `2023-01-31` | + 1 month | `2023-02-28` |
| `2024-08-31` | + 1 semester | `2025-02-28` |
| `2024-02-29` | + 1 year | `2025-02-28` |

## Weekday

`Weekday` numbers the days of the week like ISO 8601: Monday is `1` and Sunday is `7`. `Weekday::fromDate($date)` gives the day of the week of a date. A [work calendar](working-days) uses it to say which days are the weekend.



---
Last updated on 05/11/2026

