我想从数据库结果中删除00:00:00。通常我可以这样做,但是我正在使用DataTables(这对我来说是新的),所以我不知道该怎么做。
出生日期显示像
1996-04-27 00:00:00
但我需要像
27-04-1996
熟悉dataTable的人可以提出建议吗?
我在server_processing.php中的DataTables中具有以下代码。不幸的是,它并不像仅使用
"SELECT DATE_FORMAT(date, '%Y-%m-%d %H:%i') AS formated_date FROM table"
那样简单! /* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array('C_ID', 'C_Title', 'C_Surname', 'C_Forename', 'C_DOB', 'C_ID', 'C_Ref');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "C_ID";
/* DB table to use */
$sTable = "Table1";
和
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."`
FROM $sTable
$sWhereNew
$sOrder
$sLimit
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
更新
最佳答案
您可能不会喜欢它,但是解决此问题的最佳方法是在表的javascript定义中添加mRender函数:
$('#demotable').dataTable({
"aoColumnDefs": [{
"aTargets": [0]
}, {
"aTargets": [1],
"mRender": function(data, type, full) {
if (data === null) return 'N/A';
if (data === '') return 'N/A';
if (data == '0000-00-00 00:00:00') return 'N/A';
var tdat = data.split(' ');
var tedat = tdat[0].split('-');
return tedat[2] + '-' + tedat[1] + '-' + tedat[0];
}
}, ]
}
);
为什么呢?
因为这将保留原始数据的完整性,而只显示修改后的输出。很棒的事情是排序仍然有效,因为它使用原始日期!
Look at this plunker and try sorting the Date-column
更新
这是输出的图像