<?Php
$qt=mysql_query("select * from
dt_tb");
//Now let us display the data
while($nt=mysql_fetch_array($qt)){
echo "$nt[id],".date("d-m-Y : G-i",strtotime($nt[dt])).",$nt[dt2] ";
echo "<br>";
}
?>
This is how the formatting done using strtotime() and date() functions. You can change the date() function formatting based on your requirements. The output of the above script is here. 1,26-10-2004 : 0-00,2005-01-25
2,05-05-2004 : 23-56,2005-06-12
3,08-12-2005 : 13-20,2005-06-06
Here is the sql code to create and fill the table with recordsCREATE TABLE dt_tb (
id int(2) NOT NULL auto_increment,
dt datetime NOT NULL default '0000-00-00 00:00:00',
dt2 date NOT NULL default '0000-00-00',
PRIMARY KEY (id)
) TYPE=MyISAM;
#
# Dumping data for table `dt_tb`
#
INSERT INTO dt_tb VALUES (1, '2004-10-26 00:00:00', '2005-01-25');
INSERT INTO dt_tb VALUES (2, '2004-05-05 23:56:25', '2005-06-12');
INSERT INTO dt_tb VALUES (3, '2005-12-08 13:20:10', '2005-06-06');
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.