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
valiconAsked:
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

mktime
http://au2.php.net/mktime
0
DrBrainiacCommented:
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.
0
AdrianSRUCommented:
The DATE_FORMAT function should also work for you:

SELECT DATE_FORMAT(CURRENT_DATE, '%d-%m-%Y');
------------
10-08-2007

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


--Adrian
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

RoonaanCommented:
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

-r-
0

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....
0
DrBrainiacCommented:
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.
0
valiconAuthor Commented:
Thanks all. :)
0
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.