Problem with sorting date in the format dd/mm/yyyy
Problem with sorting date in the format dd/mm/yyyy
geulderack
Posts: 0Questions: 0Answers: 0
Hello, I have a problem with sorting date in the format dd / mm / yyyy, I tried to apply what you write in your example http://datatables.net/plug-ins/sorting
but it still does not work, could you help me?
Here is my html / php :
[code]
<?php require_once('Connections/ConnexionMYSQL.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_ConnexionMYSQL, $ConnexionMYSQL);
$query_RsCalendar = "SELECT DATE_FORMAT(`match`.`MATCH_DATE`, '%d/%m/%Y') AS `MATCH_DATE`,`match`.`MATCH_ID`, `match`.`TYPE_MATCH_ID`, `match`.`MATCH_TIME`, `match`.`MATCH_PLAY`, `match`.`MATCH_DOM_TEAM_ID`, `team`.`TEAM_NAME` AS `MATCH_DOM_TEAM_NAME`, `match`.`MATCH_EXT_TEAM_ID`, `team1`.`TEAM_NAME` AS `MATCH_EXT_TEAM_NAME`, `type_match`.`TYPE_MATCH_DESC`, `type_match`.`TYPE_MATCH_ID` FROM `match` INNER JOIN `type_match` ON (`match`.`TYPE_MATCH_ID` = `type_match`.`TYPE_MATCH_ID`) INNER JOIN `team` ON (`match`.`MATCH_DOM_TEAM_ID` = `team`.`TEAM_ID`) INNER JOIN `team` `team1` ON (`match`.`MATCH_EXT_TEAM_ID` = `team1`.`TEAM_ID`)";
$RsCalendar = mysql_query($query_RsCalendar, $ConnexionMYSQL) or die(mysql_error());
$row_RsCalendar = mysql_fetch_assoc($RsCalendar);
$totalRows_RsCalendar = mysql_num_rows($RsCalendar);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
$(document).ready(function() {
$('#datatables').dataTable( {
"bPaginate": false,
"bJQueryUI":true,
"oLanguage": { "sUrl": "js/fr_FR.txt" },
"aoColumns": [
{ "sType": "date-euro" },
null,
null,
null
]
} );
} );
@import "css/ui-darkness/jquery-ui-1.9.1.custom.css";
@import "css/demo_table.css";
.dataTables_info { padding-top: 0; }
.dataTables_paginate { padding-top: 0; }
.css_right { float: right; }
#example_wrapper .fg-toolbar { font-size: 0.8em }
#theme_links span { float: left; padding: 2px 10px; }
*{
font-family: arial;
}
Calendrier des matchs
Date
Heure
Rencontres
Compétition
<?php do { ?>
<?php echo $row_RsCalendar['MATCH_DATE']; ?>
<?php echo $row_RsCalendar['MATCH_TIME']; ?>
<?php echo $row_RsCalendar['MATCH_DOM_TEAM_NAME']; ?> VS <?php echo $row_RsCalendar['MATCH_EXT_TEAM_NAME']; ?>
<?php echo $row_RsCalendar['TYPE_MATCH_DESC']; ?>
<?php } while ($row_RsCalendar = mysql_fetch_assoc($RsCalendar)); ?>
<?php
mysql_free_result($RsCalendar);
?>
[/code]
Here is the javascript file associated : DateSortFr.js
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-euro-pre": function ( a ) {
if ($.trim(a) != '') {
var frDatea = $.trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
} else {
var x = 10000000000000; // = l'an 1000 ...
}
return x;
},
"date-euro-asc": function ( a, b ) {
return a - b;
},
"date-euro-desc": function ( a, b ) {
return b - a;
}
} );
[/code]
Thank you
Best regards
but it still does not work, could you help me?
Here is my html / php :
[code]
<?php require_once('Connections/ConnexionMYSQL.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_ConnexionMYSQL, $ConnexionMYSQL);
$query_RsCalendar = "SELECT DATE_FORMAT(`match`.`MATCH_DATE`, '%d/%m/%Y') AS `MATCH_DATE`,`match`.`MATCH_ID`, `match`.`TYPE_MATCH_ID`, `match`.`MATCH_TIME`, `match`.`MATCH_PLAY`, `match`.`MATCH_DOM_TEAM_ID`, `team`.`TEAM_NAME` AS `MATCH_DOM_TEAM_NAME`, `match`.`MATCH_EXT_TEAM_ID`, `team1`.`TEAM_NAME` AS `MATCH_EXT_TEAM_NAME`, `type_match`.`TYPE_MATCH_DESC`, `type_match`.`TYPE_MATCH_ID` FROM `match` INNER JOIN `type_match` ON (`match`.`TYPE_MATCH_ID` = `type_match`.`TYPE_MATCH_ID`) INNER JOIN `team` ON (`match`.`MATCH_DOM_TEAM_ID` = `team`.`TEAM_ID`) INNER JOIN `team` `team1` ON (`match`.`MATCH_EXT_TEAM_ID` = `team1`.`TEAM_ID`)";
$RsCalendar = mysql_query($query_RsCalendar, $ConnexionMYSQL) or die(mysql_error());
$row_RsCalendar = mysql_fetch_assoc($RsCalendar);
$totalRows_RsCalendar = mysql_num_rows($RsCalendar);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
$(document).ready(function() {
$('#datatables').dataTable( {
"bPaginate": false,
"bJQueryUI":true,
"oLanguage": { "sUrl": "js/fr_FR.txt" },
"aoColumns": [
{ "sType": "date-euro" },
null,
null,
null
]
} );
} );
@import "css/ui-darkness/jquery-ui-1.9.1.custom.css";
@import "css/demo_table.css";
.dataTables_info { padding-top: 0; }
.dataTables_paginate { padding-top: 0; }
.css_right { float: right; }
#example_wrapper .fg-toolbar { font-size: 0.8em }
#theme_links span { float: left; padding: 2px 10px; }
*{
font-family: arial;
}
Calendrier des matchs
Date
Heure
Rencontres
Compétition
<?php do { ?>
<?php echo $row_RsCalendar['MATCH_DATE']; ?>
<?php echo $row_RsCalendar['MATCH_TIME']; ?>
<?php echo $row_RsCalendar['MATCH_DOM_TEAM_NAME']; ?> VS <?php echo $row_RsCalendar['MATCH_EXT_TEAM_NAME']; ?>
<?php echo $row_RsCalendar['TYPE_MATCH_DESC']; ?>
<?php } while ($row_RsCalendar = mysql_fetch_assoc($RsCalendar)); ?>
<?php
mysql_free_result($RsCalendar);
?>
[/code]
Here is the javascript file associated : DateSortFr.js
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-euro-pre": function ( a ) {
if ($.trim(a) != '') {
var frDatea = $.trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
} else {
var x = 10000000000000; // = l'an 1000 ...
}
return x;
},
"date-euro-asc": function ( a, b ) {
return a - b;
},
"date-euro-desc": function ( a, b ) {
return b - a;
}
} );
[/code]
Thank you
Best regards
This discussion has been closed.