Smudly Posted September 29, 2010 Share Posted September 29, 2010 Hey, I am grabbing a date from a row in my table which is currently formatted as: date("Y-m-d") 2010-09-29 So in my code I have something like this: $row['date']; How do I use this to rearrange the date to look like: 09-29-2010 I looked at the formatting tutorials, but they explain how to format it for the date you are currently setting into a variable. Link to comment https://forums.phpfreaks.com/topic/214740-format-date-from-value-in-table/ Share on other sites More sharing options...
the182guy Posted September 29, 2010 Share Posted September 29, 2010 You do it in your MySQL SELECT query like SELECT DATE_FORMAT(`date`, '%m/%d/%Y') AS date_fmt Link to comment https://forums.phpfreaks.com/topic/214740-format-date-from-value-in-table/#findComment-1117248 Share on other sites More sharing options...
Smudly Posted September 29, 2010 Author Share Posted September 29, 2010 Alright, that may contradict with the queries I already have going. How would I modify this? $result = mysql_query("SELECT * FROM sheets WHERE artist REGEXP '^[$mysortletter]' && active='yes' && title!='' ORDER BY artist $sortcount"); Link to comment https://forums.phpfreaks.com/topic/214740-format-date-from-value-in-table/#findComment-1117250 Share on other sites More sharing options...
the182guy Posted September 29, 2010 Share Posted September 29, 2010 Try $result = mysql_query("SELECT sheets.*, DATE_FORMAT(`date`, '%m/%d/%Y') AS date_fmt FROM sheets WHERE artist REGEXP '^[$mysortletter]' && active='yes' && title!='' ORDER BY artist $sortcount"); The formatted date will be in the field date_fmt Link to comment https://forums.phpfreaks.com/topic/214740-format-date-from-value-in-table/#findComment-1117253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.