I'd suggest passing an anonymous function to the sort() method:

var dates = ['10-Jan-2013','12-Dec-2013','1-Sep-2013','15-Sep-2013'],
    orderedDates = dates.sort(function(a,b){
        return Date.parse(a) > Date.parse(b);
    });

console.log(orderedDates); // ["10-Jan-2013", "1-Sep-2013", "15-Sep-2013", "12-Dec-2013"]

var dates = ['10-Jan-2013', '12-Dec-2013', '1-Sep-2013', '15-Sep-2013'],
  orderedDates = dates.sort(function(a, b) {
    return Date.parse(a) > Date.parse(b);
  });

console.log(orderedDates);

JS Fiddle demo.

Note the use of an array ['10-Jan-2013','12-Dec-2013','1-Sep-2013','15-Sep-2013'] of quoted date-strings.

The above will give you an array of dates, listed from earliest to latest; if you want only the earliest, then use orderedDates[0].

A revised approach, to show only the earliest date – as requested in the question – is the following:

var dates = ['10-Jan-2013', '12-Dec-2013', '1-Sep-2013', '15-Sep-2013'],
    earliest = dates.reduce(function (pre, cur) {
        return Date.parse(pre) > Date.parse(cur) ? cur : pre;
    });

console.log(earliest); // 10-Jan-2013

var dates = ['10-Jan-2013', '12-Dec-2013', '1-Sep-2013', '15-Sep-2013'],
  earliest = dates.reduce(function(pre, cur) {
    return Date.parse(pre) > Date.parse(cur) ? cur : pre;
  });

console.log(earliest);

JS Fiddle demo.

References:

  • Date.parse().
  • Array.prototype.reduce().
  • Array.prototype.sort().
Answer from David Thomas on Stack Overflow
Top answer
1 of 4
25

I'd suggest passing an anonymous function to the sort() method:

var dates = ['10-Jan-2013','12-Dec-2013','1-Sep-2013','15-Sep-2013'],
    orderedDates = dates.sort(function(a,b){
        return Date.parse(a) > Date.parse(b);
    });

console.log(orderedDates); // ["10-Jan-2013", "1-Sep-2013", "15-Sep-2013", "12-Dec-2013"]

var dates = ['10-Jan-2013', '12-Dec-2013', '1-Sep-2013', '15-Sep-2013'],
  orderedDates = dates.sort(function(a, b) {
    return Date.parse(a) > Date.parse(b);
  });

console.log(orderedDates);

JS Fiddle demo.

Note the use of an array ['10-Jan-2013','12-Dec-2013','1-Sep-2013','15-Sep-2013'] of quoted date-strings.

The above will give you an array of dates, listed from earliest to latest; if you want only the earliest, then use orderedDates[0].

A revised approach, to show only the earliest date – as requested in the question – is the following:

var dates = ['10-Jan-2013', '12-Dec-2013', '1-Sep-2013', '15-Sep-2013'],
    earliest = dates.reduce(function (pre, cur) {
        return Date.parse(pre) > Date.parse(cur) ? cur : pre;
    });

console.log(earliest); // 10-Jan-2013

var dates = ['10-Jan-2013', '12-Dec-2013', '1-Sep-2013', '15-Sep-2013'],
  earliest = dates.reduce(function(pre, cur) {
    return Date.parse(pre) > Date.parse(cur) ? cur : pre;
  });

console.log(earliest);

JS Fiddle demo.

References:

  • Date.parse().
  • Array.prototype.reduce().
  • Array.prototype.sort().
2 of 4
0

This question is very old, but maybe you will find it helpful. It is going to give you the oldest date in the array.

const result = Math.min(...list.map((stringDate) => Date.parse(stringDate).getTime()))

It is returning number, so if you would love to use it as a date you have to use

new Date(result)
🌐
YouTube
youtube.com › all things javascript, llc
JavaScript Problem: Determining the Earliest or Latest Date - YouTube
The last few tutorials I seem to be on a Date object kick. In this tutorial we are going to look at how you can take an array of dates and pick the earliest ...
Published   October 8, 2020
Views   2K
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-date-exercise-12.php
JavaScript: Minimum date from an array of dates - w3resource
July 17, 2025 - Write a JavaScript function that converts an array of date strings into Date objects and returns the earliest date. Write a JavaScript function that uses a loop to iterate over an array of dates and finds the minimum date.
🌐
Make Community
community.make.com › questions
Assessing the earliest date in an array of dates - Questions - Make Community
June 19, 2023 - Hi all, There are some similar answers but I cant seem to make it work for me. When a timeline is changed for a task, a webhook is sent. I then want extract the timelines for all tasks within that group within my monday.com project board, find the earliest and latest dates, then update the ...
🌐
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 finds the maximum (latest) and minimum (earliest) dates from an array of Date objects.
🌐
Stack Overflow
stackoverflow.com › questions › 75743912 › how-can-i-find-the-oldest-date-in-an-array-of-date-objects-in-javascript
How can i find the oldest date in an array of Date objects in JavaScript? - Stack Overflow
If all dates are following the format mentioned, it's enough to string-sort that array and get the first entry, since the string is "sorted" from longest time-unit to shortest.
🌐
Stack Overflow
stackoverflow.com › questions › 58689922 › how-do-i-find-the-earliest-time-in-this-array-or-string-form
javascript - How do I find the earliest time in this array or string form? - Stack Overflow
For example, if you compare only the first 3 arrays, 10:00 will be the output as it is the earliest among the 3. ... Try the following: [["02:00","03:00"],["12:10", "13:40"], ["14:23", "16:00"], ["10:00", "20:00"]].flat().sort().shift(). ... ...
🌐
Stack Overflow
stackoverflow.com › questions › 47916691 › how-to-get-the-earliest-and-latest-dates-from-an-array-objects
javascript - How to get the earliest and latest dates from an array objects - Stack Overflow
let tasks_data = [ { 'id': 10376401, 'name': 'closed', 'notes': null, 'start_date': '2017-12-23', 'end_date': '2018-01-07', 'start_time': null, 'end_time': null, 'color': '#f99bd0', 'color_id': 5, 'estimated_hours': 0, 'done': false, 'user_id': 961775, 'project_id': null, 'project': null, 'folder_id': null, 'weight': 0, 'created_at': '2017-11-13T00:58:16.577+00:00', 'updated_at': '2017-11-13T00:58:16.577+00:00', 'deleted_at': null }, { 'id': 10438883, 'name': '', 'notes': null, 'start_date': '2018-02-17', 'end_date': '2018-02-17', 'start_time': null, 'end_time': null, 'color': '#ccaf53', 'colo
🌐
ServiceNow Community
servicenow.com › community › developer-forum › how-to-get-a-latest-date-from-an-array › m-p › 1979830
Solved: how to get a latest date from an array - ServiceNow Community
June 1, 2024 - var array = ["2019-08-28","2019-08-29","2019-09-06"]; ... Solved! Go to Solution. ... function max_date(all_dates) { var max_dt = all_dates[0], max_dtObj = new Date(all_dates[0]); all_dates.forEach(function(dt, index) { if ( new Date( dt ) > max_dtObj) { max_dt = dt; max_dtObj = new Date(dt); } }); return max_dt; } gs.print(max_date(["2019/08/28","2019/08/29","2019/09/06"]));
Find elsewhere
🌐
date-fns
date-fns.org › v1.28.5 › docs › min
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
CopyProgramming
copyprogramming.com › howto › javascript-minimum-date-from-an-array-of-dates
Finding the Earliest Date in an Array of Dates Using JavaScript - Javascript
June 13, 2023 - Compose a JavaScript function that retrieves the lowest date from an array of dates possible. The given code snippet displays the minimum date from a list of dates using the min_date function. The input to the function is an array of dates in the format YYYY/MM/DD.