This question already has an answer here:
In mysql data base the date is f=stored in the format of now() function like yyyy mm dd hh mm ss. But in frontend tool i want it like dd mm yyyy hh mm ss how can i convert it.
<?php
$addqry=mysql_query("INSERT INTO `exam` (`user_id`,`sub_id`,`q_id`,`stud_ans`,`date_time`)VALUES ('$user', '$sub', '$ans', '$stud_ans',(Now()))");
$stud_ans=' ';
if($addqry)
{
//result
$date;
$last_date=mysql_query("SELECT date_time FROM exam ORDER BY id DESC LIMIT 1; ");
while($res_last=mysql_fetch_array($last_date))
{
$date=$res_last['date_time'];
}
?>
Here it gives the datetime in the format of 2014-04-12 15:34:40 but i want it like 12-04-2014 15:34:40
</div>
try
$date=date('d-m-Y H:i:s', strtotime($res_last['date_time']));
for more :- http://php.net/manual/en/function.date.php
try this
$date_old = "2014-04-12 15:34:40";
$time_old = strtotime($date_old);
$date_new = date("d-m-Y h:i:s", $time_old);
In your While
loop use this ,
$date=date_format($res_last['date_time'],'d/m/Y H:i:s');
Easy, just split it at the space and rejoin it.
$date = split($res_last['date_time'], " ");
$date = $date[1] . " " . $date[0];
No need to translate, you can just use MySQL to do it for you, with the DATE_FORMAT
function:
SELECT DATE_FORMAT(date_time, '%d-%m-%Y %H:%i:%s');