# setDateTime

Industry: Core

## Signature

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

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

- Wraps `Temporal.PlainDateTime.prototype.with()`, which resolves every supplied field in a single atomic overflow pass — see `setDate`'s doc for why that matters over composing `addDateTime()` calls field-by-field.
- `fields` may set any of `year`, `month`, `monthCode`, `day`, `hour`, `minute`, `second`, `millisecond`, `microsecond` and/or `nanosecond`; 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: `monthCode` must be a string and every other field an integer number. `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 an era, 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 PlainDateTime string |
| `fields` | `PlainDateTimeFields` | Partial&lt;Temporal.PlainDateTimeLike&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-time. `"constrain"` clamps each field to its nearest valid value, so `month: 2` on the 31st gives Feb 29 or 28; `"reject"` returns `""`. |

## Returns

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

## Related types

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

## Examples

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

setDateTime("2024-03-10T12:00:00", { hour: 9 }) // "2024-03-10T09:00:00"
```

## Source

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