2014-09-06 70 views
-2

基於此代碼:更改日期格式d-M-Y

$tarikh = mysql_real_escape_string($_POST['tarikh']); 
    $tarikh = date('Y-m-d', strtotime($_POST['tarikh'])); 

可有人告訴我,從Y-M-d的格式轉換爲d-M-Y格式?感謝

+1

'$ tarikh =日期( 'DM-Y',的strtotime($ _ POST [ 'tarikh']));' – itachi 2014-09-06 05:14:19

+0

@itachi已經這樣做了,反而會導致0000-00 -00在數據庫中 – hicarl 2014-09-06 05:17:34

回答

1

試試這個

$tarikh = mysql_real_escape_string($_POST['tarikh']); 
$myDateTime = DateTime::createFromFormat('Y-m-d', $tarikh); 
$newDateString = $myDateTime->format('d-m-Y'); 
+0

$ tarikh = mysql_real_escape_string($ _ POST ['tarikh']); \t \t $ myDateTime = date('Y-m-d',$ tarikh); \t \t $ newDateString = $ myDateTime-> date('d-m-Y'); 它示出這個通知: 注意:用C遇到非阱,形成數值:\ XAMPP \ htdocs中\ sistem_laporan上線208 致命錯誤\ tambah_laporan.php:在非調用一個成員函數日期() -object in C:\ xampp \ htdocs \ sistem_laporan \ tambah_laporan.php在線209 – hicarl 2014-09-06 05:27:30

+1

我覺得''_POST ['tarikh']'中的日期不是有效日期,請打印'$ tarikh'來檢查到底是什麼從'$ _POST ['tarikh']' – 2014-09-06 05:40:14