I have to convert date format in to mm-dd-yyyy
I don\'t know what is the current date format it is dynamic so if I have dynamic date format is already in
Replacing - with / for m-d-Y will help.
echo date('m-d-Y',strtotime(str_replace('-', '/', $date)));
I strongly suspect that this is what's causing the problem:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
(Found in the strtotime documentation.)
You've got dash separators, so it's assuming d-m-y format, parsing it as a month of 13, and thus effectively failing.
Options I can think of off the top of my head, without being a PHP developer:
If there's a function which allows you to explicitly say what format the string is in, use that.
For example DateTime::createFromFormat()