Reputation: 185
How can I identify the date format by passing the input date
4/17/2018
17/4/2018
2018/17/4
2018/04/17
Upvotes: 1
Views: 421
Reputation: 27421
As explained in the comments, you need to check each different date format in turn until you get a valid date.
The order in which you check the different formats will depend on where the date came from. See here for the preference in different countries, but be aware that the US is really the only place that uses MDY and YDM. Elsewhere the ISO standard YMD or DMY are used.
So for the US you probably want MDY DMY YMD YDM, for China you want YMD DMY and for the rest of the world DMY YMD.
The order in which you check dates should ideally be a regional option in your system.
Upvotes: 1