Returning a MySQL date field type

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Returning a MySQL date field type

Post by TheOracle »

Hi All,

I have a field in a MySQL database with a type of DATE.

This quite obviously stores the date in it, but I want to return the value held in this field in a different format to the one it is held in.

Is there some function for this within PHP?

Many thanks
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Re: Returning a MySQL date field type

Post by harrisonad »

TheOracle wrote:I want to return the value held in this field in a different format to the one it is held in.
In english please.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

check out http://dev.mysql.com/doc/mysql/en/date- ... tions.html in the mysq manaul.
You can output the date in any format you like.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Re: Returning a MySQL date field type

Post by anjanesh »

TheOracle wrote: Is there some function for this within PHP?
Many thanks
PHP Functions.
date()
strtotime()
But I think the MySQL Date functions are better and faster.
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

thanks guys.

I have used the MySQL DATE_FORMAT function in the select
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Probably the most useful MySQL method would be UNIX_TIMESTAMP(). This'll convert a MySQL timestamp string into its equivalent UNIX timestamp, right in the query. You can then use PHP's date() function to change that into any date representation you like.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply