Php mysql CONVERT_TZ question

Hello forums , I need help with my mysql query:

When I do this:

mysql_query (SELECT  DATE_FORMAT(CONVERT_TZ(s_in, '+00:00','-4:00'), '%M %e, %Y %r %W') AS time_in FROM TABLE") 

it works

but when I do this:


$timezone = '-4:00';
$dst ='+00:00';

mysql_query (SELECT  DATE_FORMAT(CONVERT_TZ(s_in, '$dst','$timezone'), '%M %e, %Y %r %W') AS time_in FROM TABLE");

It doesn’t work

I really need the timezone to be on a string so I can make it dynamic. Any help will be praised

Tnx.

First, make a working sql query with no dynamic parts. You already did.


$sql = "SELECT  DATE_FORMAT(CONVERT_TZ(s_in, '+00:00','-4:00'), '%M %e, %Y %r %W') AS time_in FROM TABLE";

echo $sql;

Now, you can echo $sql to compare the working, non dynamic sql to the dynamic sql. Spotting the difference will be easy. Make them identical. Once you get them identical, then you can worry about using mysql query. First you must create the proper string.

Jeez a brilliant way to debug the query Tnx I forgot the user id:

$u_id = 1;
$gmt = '+8:00'; 

$sql1 ="SELECT 
						   TIME(CONVERT_TZ(s_out,'+00:00','$gmt')) AS time_out,
						   TIME(CONVERT_TZ(s_in,'+00:00','$gmt')) AS time_in                         
                           FROM sd_record WHERE user_id = '$u_id' ORDER BY id DESC LIMIT 1";

echo  $sql1;

echo '<hr>';

$sql ="SELECT 
						   TIME(CONVERT_TZ(s_out,'+00:00','+8:00')) AS time_out,
						   TIME(CONVERT_TZ(s_in,'+00:00','+8:00')) AS time_in                         
                           FROM sd_record WHERE user_id = '$u_id' ORDER BY id DESC LIMIT 1";

echo  $sql;
echo  '<br />';

$r = mysql_fetch_assoc(mysql_query($sql));
echo  $r['time_in'];