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'];
}
?>
这里以2014-04-12 15:34:40的格式给出日期时间,但我希望它像12-04-2014 15:34:40
答案 0 :(得分:4)
试
$date=date('d-m-Y H:i:s', strtotime($res_last['date_time']));
答案 1 :(得分:1)
试试这个
$date_old = "2014-04-12 15:34:40";
$time_old = strtotime($date_old);
$date_new = date("d-m-Y h:i:s", $time_old);
答案 2 :(得分:1)
答案 3 :(得分:1)
很简单,只需在空间拆分并重新加入即可。
$date = split($res_last['date_time'], " ");
$date = $date[1] . " " . $date[0];
答案 4 :(得分:1)
无需翻译,您只需使用MySQL即可使用DATE_FORMAT
函数执行此操作:
SELECT DATE_FORMAT(date_time, '%d-%m-%Y %H:%i:%s');