CyrefJS
CCyrefJS
فا
Back to documentation
Date/Since 1.38.0

startOfDay

Returns a new Date set to the first millisecond of the given day.

startOfDay(date):Date

Parameters

dateDaterequired

The date whose start of day should be returned.

Returns

Date

A new Date set to 00:00:00.000 of the given day.

Examples

01

Basic usage

Get the start of a specific day.

TypeScript
import { startOfDay } from "@cyref/js";

const date = new Date("2026-01-15T10:30:00");

const result = startOfDay(date);

console.log(result);
// 2026-01-15T00:00:00.000
02

Date without time

The function sets the time to the first millisecond of that day.

TypeScript
import { startOfDay } from "@cyref/js";

const date = new Date("2026-03-20");

const result = startOfDay(date);

console.log(result);
// 2026-03-20T00:00:00.000
03

Original date remains unchanged

startOfDay creates a new Date object, so the original date is not modified.

TypeScript
import { startOfDay } from "@cyref/js";

const date = new Date("2026-05-10T14:30:00");

const result = startOfDay(date);

console.log(date);
// 2026-05-10T14:30:00

console.log(result);
// 2026-05-10T00:00:00.000
04

Time components are reset

Hours, minutes, seconds, and milliseconds are all reset to zero.

TypeScript
import { startOfDay } from "@cyref/js";

const date = new Date("2026-08-25T18:45:32.500");

const result = startOfDay(date);

console.log(result.getHours());
// 0

console.log(result.getMinutes());
// 0

console.log(result.getSeconds());
// 0

console.log(result.getMilliseconds());
// 0
05

Date already at the start of the day

If the date is already at the start of the day, the returned Date has the same date and time value.

TypeScript
import { startOfDay } from "@cyref/js";

const date = new Date("2026-09-10T00:00:00.000");

const result = startOfDay(date);

console.log(result);
// 2026-09-10T00:00:00.000
Built with@cyref/js·Official documentation