CyrefJS
CCyrefJS
فا
Back to documentation
Date/Since 1.38.0

endOfDay

Returns a new Date set to the last millisecond of the given date.

endOfDay(date):Date

Parameters

dateDaterequired

The date whose end of day should be returned.

Returns

Date

A new Date set to 23:59:59.999 of the given date.

Examples

01

Basic usage

Get the end of a specific day.

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

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

const result = endOfDay(date);

console.log(result);
// 2026-01-15T23:59:59.999
02

Date without time

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

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

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

const result = endOfDay(date);

console.log(result);
// 2026-03-20T23:59:59.999
03

Original date remains unchanged

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

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

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

const result = endOfDay(date);

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

console.log(result);
// 2026-05-10T23:59:59.999
04

Date at the end of the day

The returned Date always uses 23:59:59.999 as its time.

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

const date = new Date("2026-08-25T06:45:12");

const result = endOfDay(date);

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

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

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

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

Date already at the end of the day

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

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

const date = new Date("2026-09-10T23:59:59.999");

const result = endOfDay(date);

console.log(result);
// 2026-09-10T23:59:59.999
Built with@cyref/js·Official documentation