![]() |
Format Date? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Format Date? (/showthread.php?tid=6735) |
Format Date? - El Forum - 03-10-2008 [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. Format Date? - El Forum - 03-10-2008 [eluser]xwero[/eluser] check out the date helper. If you want more flexibility you can use the php functions date and strtotime. Format Date? - El Forum - 03-10-2008 [eluser]Jauhari[/eluser] Any example xwero? Thanks Format Date? - El Forum - 03-10-2008 [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? Format Date? - El Forum - 03-10-2008 [eluser]xwero[/eluser] i think you have to do this Code: $fdate = "Year: %Y Month: %m Day: %d"; Format Date? - El Forum - 03-10-2008 [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 Format Date? - El Forum - 03-10-2008 [eluser]xwero[/eluser] This is the mysql_to_unix function Code: function mysql_to_unix($time = '') Format Date? - El Forum - 03-10-2008 [eluser]Jauhari[/eluser] Hi xwero Thanks you fast reply, so it's will be better use strtotime than mysql_to_unix? Format Date? - El Forum - 03-10-2008 [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. |