Jump to content

How to change the date format?


Wayniac

Recommended Posts

Hello everyone,

 

I'm attempting to convert my date format for mysql database from YYYY-MM-DD to MM-DD-YYYY. It seems to say it works to my little understanding of this process, but nothing changes.

 

This is the SQL code I used in phpmyadmin.

SELECT DATE_FORMAT(CURDATE(), '%m/%d/%Y')

 

This is the message I got afterwards.

06/30/2010

 

If I browse that field in phpmyadmin, it still shows the following format:

0000-00-00

 

Any suggestions? Thank you everyone.

Link to comment
Share on other sites

Thank you for your quick reply PFMaBiSmAd.

 

So do you mean I would have to run this through a php query? Also, do you have enther an example or know of any tutorials that demonstrate this. I'm having a hard time finding such a thing, I figured this would be a pretty standard procedure given how common it is on the web.

Link to comment
Share on other sites

If I attempt to paste the following into the phpmyadmin SQL section:

SELECT DATE_FORMAT(date_ship, '%m/%d/%Y')

 

It gives me this error:

Error

SQL-query : 

SELECT DATE_FORMAT( date_ship, '%m/%d/%Y' )

MySQL said:

Unknown column 'date_ship' in 'field list'

Back

 

There is indeed a field with this exact spelling "date_ship" in the table.

Link to comment
Share on other sites

Once again, thank you so much. But was I suppose to run this query through a php code?

 

This is what happens when I enter it in the phpmyadmin SQL section:

DATE_FORMAT( date_ship, '%m/%d/%Y' )
00/00/0000

 

Which is great, but when I browse the fields section, its still 0000/00/00? You said earlier the database format never changes, how would I approach this then?

 

Thank you

Link to comment
Share on other sites

Sorry, I'm not usually this confused, perhaps I'm just really tired. Could you tell me how I can get my field "ship_date" which is on my webpage that sends off the data to my mysql database when submitted to either be stored as MM-DD-YYYY or when I try an retrieve it on my other page that views the entry to be displayed as MM-DD-YYYY.

 

Sorry if I'm making this difficult for you, I really do appreciate you helping me.

Link to comment
Share on other sites

how I can get my field "ship_date" which is on my webpage that sends off the data to my mysql database when submitted to either be stored as MM-DD-YYYY

 

^^^ You don't. You take the MM-DD-YYYY submitted value and you reformat it as a standard YYYY-MM-DD value to be inserted into your table. Since you are probably breaking the submitted value into its' individual parts in order to validate it, it is easiest to simply put it back together in the correct format. Another way to change a MM-DD-YYYY format into a YYYY-MM-DD format would be to use the mysql STR_TO_DATE() function in your INSERT query.

 

... when I try an retrieve it on my other page that views the entry to be displayed as MM-DD-YYYY.

 

^^^ That would be where you would use the the DATE_FORMAT() function in a query.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.