Hi. Ive come stuck where im transferring data from an old database so i can tidy it up, but the dates are a mish mash of formats.
I.e. 18/05/1983 , 29.12.1972 ect.
If i do Carbon::parse($old_date->dob); I get an error that it has failed to parse.
How would i do some sort of check and change the date to a standard date like 'Y-m-d'?
Is there a Carbon method that can figure out what format it is and change it?
Is there a Carbon method that can figure out what format it is and change it?
No.
You'd have to do this manually. How much data are you working with? You can check if the date has .'s or /'s and convert it by specifying the format that it needs to parse, but there's also another problem.
Let's say the date was
11/05/1983 or 11.05.1983
How would you know for sure which is the month, and which is the day, if all of the dates aren't stored in a consistent format? If one of the 2 numbers was greater than 12, it's obviously the day, but what if both numbers were <= 12?