Skip to content

startOfDay()

startOfDay(input): Date

Defined in: utils/date/startEndOfDay.ts:29

Get the start of the day (local time) for a given date-like value.

This helper:

  • Accepts Date, ISO-like string, or timestamp number.
  • Converts the value via toDateStrict.
  • Returns a new Date instance set to 00:00:00.000 local time.
  • Never mutates the input Date.

Parameters

input

Date-like value representing the day you want to normalize.

string | number | Date

Returns

Date

A new Date object at local midnight (00:00:00.000) of that day.

Throws

When input cannot be converted into a valid Date (as determined by toDateStrict).

Example

ts
const d = new Date(2024, 0, 10, 15, 30, 45, 123); // 2024-01-10 15:30:45.123
const start = startOfDay(d);
// start -> 2024-01-10 00:00:00.000 (local time)

Released under the MIT License.