# setDate

Industry: Core

## Signature

```ts
setDate(value: string, fields: PlainDateFields, options?: { overflow?: "reject" | "constrain" | undefined; }): string
```

Return a PlainDate ISO string with the given `fields` set on `value`.

- Wraps `Temporal.PlainDate.prototype.with()`, which resolves every supplied field in a single atomic overflow pass. This is the safe alternative to composing `addDate()` calls field-by-field: each sequential `.add()` resolves overflow against its own intermediate value, so setting month-then-day vs. day-then-month on the same target can silently diverge — `.with()` has no such order-dependence.
- `fields` may set `year`, `month`, `monthCode` and/or `day`; omitted fields keep their current value. An object with no field set, such as `{}` or `{ year: undefined }`, is a no-op.
- Values are not converted: `year`, `month` and `day` must be integer numbers and `monthCode` a string. `null`, a numeric string, a boolean or a fraction returns "", where Temporal would convert or truncate it. A bigint, `NaN` or an infinity returns "" too. A number too large for its field follows `overflow`. A month or day below 1, or a date outside Temporal's range, returns "".
- An own key that is not one of these fields, such as a misspelt `yaer`, returns "". So does a field this function does not take, such as `hour`, or a `calendar` or `timeZone` property, whether own, inherited or a getter. A field is read with a property get, as Temporal reads it, so an inherited or getter field is set.
- A Temporal date or time object returns "", as Temporal's `with` refuses one. One whose prototype has been replaced with `Object.prototype`, `null` or `Function.prototype` sets nothing instead.
- Returns "" for invalid input.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO PlainDate string |
| `fields` | `PlainDateFields` | Partial&lt;Temporal.PlainDateLike&gt; object specifying fields to set |

## Options

**options**

How an out-of-range field value is handled

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `overflow?` | `"reject"` \| `"constrain"` ([`Overflow`](/gmt/reference/types/Overflow/)) | `"constrain"`, Temporal's default. | What to do when the fields do not form a real date. `"constrain"` clamps to the last valid day, so `month: 2` on the 31st gives Feb 29 or 28; `"reject"` returns `""`. |

## Returns

ISO PlainDate string with fields set, or "" on invalid input

## Related types

- [`Overflow`](/gmt/reference/types/Overflow/)

## Examples

```ts
import { setDate } from "@northguild/gmt/plain/calculate";

setDate("2024-03-10", { year: 2025 }) // "2025-03-10"
```

## Source

[plain/calculate/setDate.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/calculate/setDate.ts)
