FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Format date come from database!





AOP Web Development
Do you have any idea on how to format a date coming from the database because i don't have any idea on how to format the date...

Since the format of the date in mysql is YYYY-mm-dd. All i want is to change the format

for example if i have 2

007-02-28

and i want to format it like

February 20,2007

is it possible?

Rolling Eyes Question Question
MrBlueSky
Go here: http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html and Ctrl-F search for "DATE_FORMAT". That's the function you are looking for.
AOP Web Development
MrBlueSky wrote:
Go here: http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html and Ctrl-F search for "DATE_FORMAT". That's the function you are looking for.


I already try that using the date_format function in the mysql query but all i need is want is i can format it just like date() function in php.
SlowWalkere
I originally wanted to do a similar thing, since it seemed to make sense to store a date in the DATE format (since mySQL had one). However, I found it easier to use a Unix timestamp instead, stored in an int.

Use time() to get the current timestamp of the date that you want to save and store it in the database.

When you retrieve it, use the date() function to format it in whatever way you like. There's plenty of different formatting options (all docc'ed on PHP.net).

For example, February 20, 2007 would be...
date("F j, Y", $time);

However, the link that was provided before about DATE_FORMAT will do the same thing through mySQL's select statement, if the item is stored in an actual date or timestamp type in the database.

Code:
SELECT DATE_FORMAT(date, '%M %e, %Y);


- SlowWalkere
AOP Web Development
thanks to all dude but i already found how to do it

strftime("%B %d,%Y",strtotime("12/23/2004"));


the output will goes to

December 23,2004


Thanks to all who replies!
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.