I have gone through convert php date to mysql format but still I have few issues and questions,
In general, my application, can input dates in Y-m-d, d-m-y, m-d-Y, jS, F Y format, or even with '/' separator.
I want this dates to be converted in to MYSQL Y-m-d format,
I tried as below, but it shows different output than expected,
Non working
date_format(date_create_from_format('d-m-Y', '02-25-2016'), 'Y-m-d');
Working
date_format(date_create_from_format('d-m-Y', '25-02-2016'), 'Y-m-d');
So it seems format and string to be match in same way, otherwise its not interpreting correctly,
What is best way to convert above 4 format inputs to mysql(Y-m-d) format?
Thanks advanced,
date_create_from_format('d-m-Y', '02-25-2016')to work? How many years have 25 months? Of course the date value and the format mask have to match..... that's the whole point ofdate_create_from_format()!!!01-02-2016.... is that 1st February, or 2nd January? PHP will make a decision for you based on/or-separator, but there's no guarantee that it will be correct..... you need to control the date formats that you use so that you can eliminate ambiguities.... the whole point of thedate_create_from_format()function is for you to tell PHP what format the date is, so that is parser can make the right decision