![]() |
Reformat XML 'date' output. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Reformat XML 'date' output. (/showthread.php?tid=13192) |
Reformat XML 'date' output. - El Forum - 11-13-2008 [eluser]Poccuo[/eluser] If I have a DB row full of dates in this format: 2008-07-03 2008-06-01 2008-04-16 And I'd like to export them in XML in the following format: 07.03.08 06.01.08 04.16.08 I'm able to successfully export them in the former format via the following code: Code: $query = $this->db->query("SELECT date FROM news"); But I'm not sure what steps would be necessary to convert the query values to the format I desire. Please help! Reformat XML 'date' output. - El Forum - 11-14-2008 [eluser]gRoberts[/eluser] using strtotime to parse the date, you could then output it using date to any format you wish... Reformat XML 'date' output. - El Forum - 11-14-2008 [eluser]Poccuo[/eluser] Thanks for your response. While it is true that this is one way to get the dates formatted, what I was not able to reason was how to save the newly formatted values back into the "$query" variable and then have them sent to the xml_from_result function. My solution is as follows and relies on the MYSQL code to format the date for output. This is an awfully convenient solution to the problem. Code: $query = $this->db->query("SELECT DATE_FORMAT(date, '%m.%d.%y') as date_formatted FROM news ORDER BY date DESC"); Do you see any reason not to go this route? For the sake of learning a little, could you show me how you'd take those formatted dates and store them back into the $query variable? I'm always up for learning something new! |