Jump to content

[SOLVED] How to change date format with php?


divadiva

Recommended Posts

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>


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";

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);


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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.