CxJS

zeroTime

import { zeroTime } from 'cx/util'; Copied

Sets the time portion of a date to midnight (00:00:00.000).

Signature

function zeroTime(date: Date): Date

Examples

const date = new Date("2026-01-21T14:30:45.123");
const midnight = zeroTime(date);
// 2026-01-21T00:00:00.000

// Original is unchanged
console.log(date.getHours()); // 14
console.log(midnight.getHours()); // 0

Use Cases

Date comparison

function isSameDay(d1: Date, d2: Date): boolean {
  return zeroTime(d1).getTime() === zeroTime(d2).getTime();
}

Date range queries

const startOfDay = zeroTime(new Date());
const endOfDay = new Date(startOfDay);
endOfDay.setDate(endOfDay.getDate() + 1);

const todaysRecords = records.filter(
  (r) => r.date >= startOfDay && r.date < endOfDay
);

See Also