0

How can I do to display the field DATA_ACQUISTO so that it can be read correctly and it is not saved in that timestamp?

I want to be viewed properly "day, month, year, etc."

<?php
$connection = @mysql_connect('localhost', 'NAME', 'PASSW');
mysql_select_db('DATABASE_NAME');

$query = "SELECT  * FROM XXXXXXX  ";

$result = mysql_query($query);
echo "<table>"; // start a table tag in the HTML
while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results
    echo "<tr><td><b>Nickname  :</b>" . $row['Utente'] . "</td><td><b>Email  :</b>" . $row['Email'] .  "</td><td><b>Data Acquisto  :</b>" . $row['Data_Acquisto'] . "</td></tr>" ;  //$row['index'] the index here is a field name
}

echo "</table>"; //Close the table in HTML

mysql_close(); //Make sure to close out the database connection

?>

I have varchar(20) ike "Data_Acquisto" and with this variable I set the date where I entered the record in this way: "$a=time();"

I need to show view DATA ACQUISTO in a normal format and not in timestamp. So I'd like to know how can I convert it and show the result Screen

Smern
  • 18,746
  • 21
  • 72
  • 90
  • Welcome to Stack Overflow! This question is a little short on information. What do you mean by "read correctly"? What is "DATA_AQUISITO"? Is it a date which needs formatting? – Jay Blanchard Apr 14 '15 at 12:28
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo). – Jay Blanchard Apr 14 '15 at 12:28
  • i have varchar(20) ike "Data_Acquisto" and with this variable I set the date where I entered the record in this way: "$a=time();" – user3055211 Apr 14 '15 at 13:15

2 Answers2

0

Thats show you correct date if you have in Mysql Data_Acquisto row as Date type.

 $date = date('d.m.Y H:i',strtotime($row["Data_Acquisto"]));
 echo $date;
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
0

You can show date using strtotime with date function like as below

$date = date("d-m-Y",strtotime($row['Data_Acquisto']));
if you want to show time also just pass "d-m-Y H:i:s".

If you want to compare date in query like

"select * from table_name where date >= STR_TO_DATE( SUBSTRING_INDEX( field_name, ',', 1 ) , '%Y%m%d')';
  • This does not convert the date timestamp of the time now, but in a wrong date why? https://docs.google.com/file/d/0B2Xt3DqxNeZpdGo4aWhpUS1tN2M/edit?usp=drivesdk – user3055211 Apr 14 '15 at 13:36
  • Can you please post your script that you have try to display date. ? because I already use this script to display date from values which is store as varchar data type in data base. – Jgandhi Apr 15 '15 at 05:49