Trouble with an Array of dates

Options
hello
I have the following returned array:
[
05/03/2009,
03/02/2022,
30/09/2020,
25/10/2021,
11/01/2022,
02/02/2022,
01/02/2021,
01/02/2022,
25/10/2021
]

I am trying to extract the oldest date from the array.

I have not been successful using the sort function. Not sure there is a native date sorting function?

I have tried to loop through to change the dates to timestamp, however for some reason the third date  30/09/2020 throws an error for the totimestamp function, I'm not sure why.

Any advice on the best way to get the oldest date out?

Many thanks.


/

Comments

  • Simon Parslow
    Options
    Ok I made it work.

    The reason the 3rd date was causing an error converting to a timestamp is because the date format wasn't recognized, it wanted to see the format m/d/Y instead of what my array had d/m/Y.

    So I used substr and concat to re format the date, and then the conversion to timestamp worked fine. 

    I then created a new array made up of the time stamp values. And sorted them into an ascending list.

    Then I removed the first value from the list, stored it as a variable and then formatted this back to d/m/Y for my output of the oldest date.

    If anyone knows a better way please let me know as I learning (fast).