Skip to content
Advertisement

Get most recent date from an array of dates in “Y-m-d H:i:s” format

I have the array of dates in Y-m-d H:i:s format like:

JavaScript

I would like to know the most recent date.

In other words, today is June 13th 2012, which datetime is closest to today’s date?

From my sample array, I am expecting 2012-06-11 08:30:49.

How can I do that?

Advertisement

Answer

Do a loop, convert the values to date, and store the most recent, in a var.

JavaScript

something like that… you get the idea If you want most recent BEFORE today :

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement