Date/Since
1.38.0endOfDay
Returns a new Date set to the last millisecond of the given date.
endOfDay(date):DateParameters
dateDaterequiredThe date whose end of day should be returned.
Returns
DateA 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.99902
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.99903
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.99904
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());
// 99905
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.999Built with@cyref/js·Official documentation