Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/date_fns/index.js>closestTo

date-fns Deno package
Go to Latest
function closestTo
import { closestTo } from "https://deno.land/x/date_fns@v2.12.0/index.js";

Examples

// Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030? var dateToCompare = new Date(2015, 8, 6) var result = closestTo(dateToCompare, [ new Date(2000, 0, 1), new Date(2030, 0, 1) ]) //=> Tue Jan 01 2030 00:00:00

Parameters

dirtyDateToCompare
  • the date to compare with
dirtyDatesArray
  • the array to search