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>


Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.