How to change date format in MySQL from a PHP form submission

Hi all,

I have a PHP form that submits data to a MySQL database. Users can search for records or add and delete records from their browsers as it is running in PHP. However MySQL date format is in Y-M-D and I need it to be M-D-Y. What would be the easiest way to do this?  I will need help with the code also. Thanks
LVL 12
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kiran Paul VJComputer EngineerCommented:
i didnt get it clearly.
anyway check this

Best way is to save all dates and times as a unix timestamp in you database. Then you can use functions like mktime(0,0,0,$month,$day,$year) (mentioned above) to generate a timestamp, and date("m-d-Y,$timestamp) to convert the timestamp to a readable date in your desired format.
The DATE_FORMAT function should also work for you:


With this method you can take care of the date formatting in the query instead of leaving it for your PHP code.

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Personally I would go with
SELECT UNIX_TIMESTAMP(your_date_or_datetimefield) as field FROM table,

That would retrieve a timestamp for your date/datetime field.

The actual output of the date would then be on your output/template part. You'd define a configuration constant containing a site-wide date format, and apply it to the timestamp.
define('DATE_SIMPLE', '%m-%d-%Y')

echo strftime(DATE_SIMPLE, $row['field']);

You'd probably get a warning that your locales need to be set first. This would depend on your php install though


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
valiconAuthor Commented:
Could you give me a few code examples?  I need to know how to work this into my code....
The code of Roonaan is practicly all you need and better then my code. If you post your code, we can help you integrate it.
valiconAuthor Commented:
Thanks all. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.