423,851 Members | 2,762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,851 IT Pros & Developers. It's quick & easy.

How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?

P: n/a
Hi everybody,

I just curious about change date(0000-00-00) to date (00-00-0000) in
mysql.Can anyone tell me about that.

Thanks.
izmanhaidi.
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
MyOracle wrote:
I just curious about change date(0000-00-00) to date (00-00-0000) in
mysql.Can anyone tell me about that.


use strtotime() to convert the mysql datetime format into a timestamp, and
then date() to convert it into your chosen format.

eg print date(strtotime($mysql_date), "d-m-Y"))

Refer to the manual pages for more info at:

http://www.php.net/strtotime
http://www.php.net/date

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 20 '05 #2

P: n/a
MyOracle wrote:
I just curious about change date(0000-00-00) to date (00-00-0000) in
mysql.Can anyone tell me about that.


Read about the DATE datatype and its relatives here:
http://dev.mysql.com/doc/mysql/en/DATETIME.html

MySQL always stores and retrieves date values in YYYY-MM-DD format.
You must use this format when inputting date values.

You can reformat output of date values in a SELECT using the
DATE_FORMAT() function. See:
http://dev.mysql.com/doc/mysql/en/Da...functions.html

Regards,
Bill K.
Jul 20 '05 #3

P: n/a
Chris Hope wrote:
MyOracle wrote:
I just curious about change date(0000-00-00) to date (00-00-0000) in
mysql.Can anyone tell me about that.


use strtotime() to convert the mysql datetime format into a timestamp, and
then date() to convert it into your chosen format.

eg print date(strtotime($mysql_date), "d-m-Y"))

Refer to the manual pages for more info at:

http://www.php.net/strtotime
http://www.php.net/date


Actually Bill's post is better. I must have been half asleep when I read
your post and was thinking I was posting a reply to a PHP group. If you are
coding in PHP then my solution works in your PHP script, otherwise check
out his post as you can reformat the date in MySQL itself.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 20 '05 #4

P: n/a

SELECT DATE_FORMAT(pubdate, '%e-%m-%Y') AS date FROM mytable
for 5-09-2004

SELECT DATE_FORMAT(pubdate, '%d-%m-%Y') AS date FROM mytable
for 05-09-2004

I prefer the first one, so I can easilly replace the -09- by the month name
in the page language.

:)
Wouter
"MyOracle" <iz********@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
: Hi everybody,
:
: I just curious about change date(0000-00-00) to date (00-00-0000) in
: mysql.Can anyone tell me about that.
:
: Thanks.
: izmanhaidi.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.