Code is tested with IE,FF,Chrome and works properly:

var dates=[];
dates.push(new Date("2011/06/25"))
dates.push(new Date("2011/06/26"))
dates.push(new Date("2011/06/27"))
dates.push(new Date("2011/06/28"))
var maxDate=new Date(Math.max.apply(null,dates));
var minDate=new Date(Math.min.apply(null,dates));
Answer from Andrew D. on Stack Overflow
🌐
Reddit
reddit.com › r/learnjavascript › how to get minimum date from array of object
r/learnjavascript on Reddit: How to get minimum date from array of object
October 25, 2021 -

Hello,

I would like to get the minimum date of this array of objects bellow:

let activities = [
  { title: 'Hiking', date: '2019-06-13' },
  { title: 'Shopping', date: '2019-06-10' },
  { title: 'Trekking', date: '2019-06-22' },
  { title: 'Trekking', date: null }
]

let sortedActivities = activities.sort((a, b) => new Date(a.date) - new Date(b.date))
console.log(sortedActivities[0])

The problem is when date activities.date is null it always returns null .

What's the best way to reject null value from this comparison ?

Thanks

🌐
W3Resource
w3resource.com › javascript-exercises › javascript-date-exercise-12.php
JavaScript: Minimum date from an array of dates - w3resource
July 17, 2025 - // Define a JavaScript function ... to store the minimum date and its corresponding Date object var min_dt = all_dates[0], min_dtObj = new Date(all_dates[0]); // Iterate through each date in the array using forEach method ...
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › date › min or max date
Find the minimum or maximum date using JavaScript - 30 seconds of code
January 6, 2024 - This means that, much like any other number, you can compare them and perform mathematical operations on them. Based on this observation, we can use the Math.min() and Math.max() methods to find the minimum or maximum date in an array of dates.
🌐
Medium
medium.com › @luke.sloanebulger › how-to-find-the-min-and-max-dates-in-a-javascript-array-baa6dd5deb66
How To Find The Min and Max Dates in a JavaScript Array? | by Luke Sloane-Bulger | Medium
November 3, 2023 - To get the min and max date from an array of dates in JavaScript, we can use the Math.min() and Math.max() static methods. Then using the spread operator ... on the array to pass each date as an argument in the Math.min() and Math.max() converts ...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-select-min-max-dates-in-an-array-using-javascript
How to Select Min/Max Dates in an Array Using JavaScript? | GeeksforGeeks
December 31, 2024 - The code uses reduce() to iterate through the dates array, comparing two dates (a and b) at a time. It finds: Minimum date (minDate): By keeping the smaller of a and b.
🌐
Plain English
plainenglish.io › home › blog › javascript › how to get the min and max dates in a javascript date array?
How to Get the Min and Max Dates in a JavaScript Date Array?
March 23, 2023 - In this article, we’ll look at how to the min and max dates in a JavaScript date array. We can use the Math.max and Math.min methods to get the max and min dates respectively.
Find elsewhere
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-get-the-min-and-max-dates-in-a-javascript-date-array-1fee265b7cdf
How to Get the Min and Max Dates in a JavaScript Date Array? | by John Au-Yeung | JavaScript in Plain English
March 23, 2023 - In this article, we’ll look at how to the min and max dates in a JavaScript date array. We can use the Math.max and Math.min methods to get the max and min dates respectively.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-max-min-date-in-array-of-objects
Get the Max/Min Date in an Array of Objects in JavaScript | bobbyhadz
We used the spread syntax (...), because the Math.max() and Math.min() functions expect multiple, comma-separated numbers, which means we can't directly pass an array. This works because each date stores a timestamp under the hood.
🌐
IQCode
iqcode.com › code › javascript › find-min-and-max-date-in-array-javascript
find min and max date in array javascript Code Example
September 19, 2021 - Math.max(1, 2, 3) // 3 Math.min(1, 2, 3) // 1 var nums = [1, 2, 3] Math.min(...nums) // 1 Math.max(...nums) // 3
🌐
Tutorial Reference
tutorialreference.com › javascript › examples › faq › javascript-how-to-get-max-min-date-in-an-array
How to Get the Max or Min Date in an Array in JavaScript | Tutorial Reference
Finding the maximum or minimum date in an array is a simple task once you understand that Date objects can be compared as numbers. The core principle is to use Math.max() or Math.min() on the Date objects (or their timestamps) and then convert the result back to a Date with new Date(). For an ...
🌐
CodePal
codepal.ai › code-generator › query › p84uWZzq › javascript-function-get-min-date
JavaScript Function: Get Minimum Date from Array - CodePal
Please provide a valid array of Date objects."); } // Find the minimum date using the reduce method const minDate = dates.reduce((min, date) => (date < min ? date : min), dates[0]); return minDate; } // Usage Example const dateArray = [new ...
🌐
Piyush Mishra
codingwithpiyush.com › home › blog › getting the max/min dates in an array of objects with javascript
Getting The Max/Min Dates In An Array Of Objects With JavaScript | Piyush Mishra
December 22, 2023 - // Temporal Challenge Solution: ... = maxDate.getTime() - minDate.getTime(); return timeDifference; } ... calculateTimeDifference function takes an array of date objects as a parameter, finds the maximum and minimum dates ...
🌐
The Web Dev
thewebdev.info › home › how to get the min and max dates in a javascript date array?
How to Get the Min and Max Dates in a JavaScript Date Array? - The Web Dev
September 2, 2022 - We can use the Math.max and Math.min methods to get the max and min dates respectively. ... const dates = []; dates.push(new Date("2011/06/25")) dates.push(new Date("2011/06/26")) dates.push(new Date("2011/06/27")) dates.push(new Date("2011/06/28")) ...
🌐
Decipher
decipher.dev › mindate
minDate | 30 Seconds of Typescript - Decipher.dev
Use the ES6 spread syntax to find the minimum date value, new Date() to convert it to a Date object. const minDate = (dates) => new Date(Math.min(...dates)); const array = [ new Date(2017, 4, 13), new Date(2018, 2, 12), new Date(2016, 0, 10), ...
🌐
TutorialsPoint
tutorialspoint.com › sort-array-based-on-min-and-max-date-in-javascript
Sort array based on min and max date in JavaScript?
We are required to write a JavaScript function that takes in one such array. The function should find the oldest and the newest date from this array.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-get-min-date-from-array
How to Get Minimum Date from an Array in TypeScript
const dates: Date[] = [new Date('2022-01-15'), new Date('2022-03-10'), new Date('2022-02-05')]; const minDate = new Date(Math.min(...dates.map(date => date.getTime()))); console.log('Minimum Date:', minDate); Another approach is to use the Array.reduce method to iterate over the array and keep ...