Format Date? |
[eluser]Jauhari[/eluser]
I have some question about MySQL date format and I want convert it to more better view format. My MySQl format is like this 2008-02-04 and I want display my MySQL data date become like this 11/03/2008 or Like this Monday, 10 January 2008 or something else. and When I make update the date format will be automatically back to 2008-02-04 format. How to do that? Please give me solutions.
[eluser]xwero[/eluser]
check out the date helper. If you want more flexibility you can use the php functions date and strtotime.
[eluser]Jauhari[/eluser]
I was try with this code Code: $fdate = "Year: %Y Month: %m Day: %d"; And got this result and error. Code: A PHP Error was encountered What's wrong?
[eluser]xwero[/eluser]
i think you have to do this Code: $fdate = "Year: %Y Month: %m Day: %d";
[eluser]Jauhari[/eluser]
I have do this Code: echo mdate($fdate, strtotime($row->tanggal)); And produce the some result, can anyone show me different between mysql_to_unix and strtotime? Thanks
[eluser]xwero[/eluser]
This is the mysql_to_unix function Code: function mysql_to_unix($time = '')
[eluser]Jauhari[/eluser]
Hi xwero Thanks you fast reply, so it's will be better use strtotime than mysql_to_unix?
[eluser]mironcho[/eluser]
Hi Jauhari, Other possible solution is to use MySQL DATE_FORMAT() function in your sql code: Code: SELECT DATE_FORMAT(your_date_field, 'Year: %Y Month: %m Day: %d') AS formated_date FROM your_table; If you prefer to format it in php - probably strtotime will be faster than mysql_to_unix. |
Welcome Guest, Not a member yet? Register Sign In |