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
Returning a MySQL date field type
Moderator: General Moderators
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
Re: Returning a MySQL date field type
In english please.TheOracle wrote:I want to return the value held in this field in a different format to the one it is held in.
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.
You can output the date in any format you like.
Re: Returning a MySQL date field type
PHP Functions.TheOracle wrote: Is there some function for this within PHP?
Many thanks
date()
strtotime()
But I think the MySQL Date functions are better and faster.
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.