Bonjour a tous,

J'ai un code qui utilise la fonction CONVERT_TZ().
J'ai le code suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
include ('includes/header.html');
date_default_timezone_set();
if (isset($_SESSION['user_tz'])) {
	$first="CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
	$last="CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
} else {
	$first='p.posted_on';
	$last='p.posted_on';
}
$q= "SELECT t.thread_id, t.subject, username, COUNT(post_id)-1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id=u.user_id WHERE t.lang_id={$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
$r=mysqli_query($dbc, $q);
if(mysqli_num_rows($r) > 0) {
	echo '<table width="100%" border = "2" callspacing="2" cellspading="2" align="center">
	<tr>
	<td align="left" width="50%"><em>' . $words['subject'] . '</em>: </td>
	<td align="left" width="20%"><em>' . $words['posted_by'] . '</em>: </td>
	<td align="left" width="10%"><em>' . $words['posted_on'] . '</em>: </td>
	<td align="left" width="10%"><em>' . $words['replies'] . '</em>: </td>
	<td align="left" width="10%"><em>' . $words['latest_reply'] . '</em>: </td>
	</tr>';
 
	while ($row=mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		echo '<tr>
		<td align="left"><a href="read.php?tid=' . $row['thread_id'] . '">' . $row['subject'] . '</a></td>
		<td align="left" >' . $row['username'] . ' </td>
		<td align="left" >' . $row['first'] . '</td>
		<td align="left" >' . $row['responses'] . '</td>
		<td align="left" >' . $row['last'] . '</td>
		</tr>';
	}
	echo '</table>';
} else {
	echo '<p> There are currently no messages in this forum. </p>';
}
include ('includes/footer.html');
?>
Dans mon navigateur. j'obtiens un avertissement:

Warning: date_default_timezone_set() expects exactly 1 parameter, 0 given in D:\wamp\www\PHP-TESTS\forum.php on line 3
Si je remplace directement, $first et $last par p.posted_on dans la requete suivante:

$q= "SELECT t.thread_id, t.subject, username, COUNT(post_id)-1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id=u.user_id WHERE t.lang_id={$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
j'arrive a obtenir les dates. Mais moi je souhaite convertir les dates avant de les afficher.
Comment puis je faire pour enlever cet avertissement?

Merci d'avance.

Best,
Billy