divadiva Posted January 27, 2009 Share Posted January 27, 2009 Experts, Database:MYSQL As mysql date take yyyy-mm-dd.Is there a way to display it as mm-yyyy.I want to change the display at front end? Here is the code: $ToolDataQuery = "SELECT i.in_production , l.loc_name FROM inventory i LEFT JOIN locations l USING (loc_ref) WHERE i.inventory_id = $ref"; if ($ToolDataQueryResultRow['in_production'] != ''){?> <tr> <td align="right" valign="top" bgcolor="#edda74" width="120"><strong>In Production:</strong></td> <td><? print $ToolDataQueryResultRow['in_production'] ?></td> </tr> Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/ Share on other sites More sharing options...
bluesoul Posted January 27, 2009 Share Posted January 27, 2009 Take a look at date() and you should find the exact method of displaying that you want. Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/#findComment-747931 Share on other sites More sharing options...
pocobueno1388 Posted January 27, 2009 Share Posted January 27, 2009 Take a look at MySQL's DATE_FORMAT() function. Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/#findComment-747932 Share on other sites More sharing options...
premiso Posted January 27, 2009 Share Posted January 27, 2009 Not sure which is your date column, but this would work if in_production is your column: $ToolDataQuery = "SELECT DATE_FORMAT(i.in_production, '%Y-'%c) as in_production, l.loc_name FROM inventory i LEFT JOIN locations l USING (loc_ref) WHERE i.inventory_id = $ref"; Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/#findComment-747933 Share on other sites More sharing options...
divadiva Posted January 27, 2009 Author Share Posted January 27, 2009 Thankyou all for replying. Permiso when I run this query I get this warning: Database has field in_production. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/testsite/ToolDataSheet.inc on line 9 $ToolDataQuery = "SELECT i.wafer_max,date_format(inventory.in_production,'%m-%y') AS i.in_production ,i.footprint, l.loc_name FROM inventory i LEFT JOIN locations l USING (loc_ref) WHERE i.inventory_id = $ref"; //print $ToolDataQuery; $ToolDataQueryResult = mysql_query($ToolDataQuery); $ToolDataQueryResultRow = mysql_fetch_array($ToolDataQueryResult); Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/#findComment-747942 Share on other sites More sharing options...
premiso Posted January 27, 2009 Share Posted January 27, 2009 Thankyou all for replying. Permiso when I run this query I get this warning: Database has field in_production. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/testsite/ToolDataSheet.inc on line 9 $ToolDataQuery = "SELECT i.wafer_max,date_format(inventory.in_production,'%m-%y') AS i.in_production ,i.footprint, l.loc_name FROM inventory i LEFT JOIN locations l USING (loc_ref) WHERE i.inventory_id = $ref"; //print $ToolDataQuery; $ToolDataQueryResult = mysql_query($ToolDataQuery); $ToolDataQueryResultRow = mysql_fetch_array($ToolDataQueryResult); You have an error in that sql. $ToolDataQuery = "SELECT i.wafer_max,date_format(inventory.in_production,'%m-%y') AS i.in_production ,i.footprint, l.loc_name FROM inventory i LEFT JOIN locations l USING (loc_ref) WHERE i.inventory_id = $ref"; //print $ToolDataQuery; $ToolDataQueryResult = mysql_query($ToolDataQuery) or die("MySQL Error for Query: $ToolDataQuery <br /> MySQL Returned: " . mysql_error(); $ToolDataQueryResultRow = mysql_fetch_array($ToolDataQueryResult); My bet is that in_production is not a datetime field in mysql. Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/#findComment-747958 Share on other sites More sharing options...
divadiva Posted January 27, 2009 Author Share Posted January 27, 2009 Silly me .It was fixed I didnt realised.Here is what I did: date_format(i.in_production,'%M,%Y') as in_production Thanks Premiso once again . Link to comment https://forums.phpfreaks.com/topic/142693-solved-how-to-change-date-format-with-php/#findComment-747973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.