CONVERT_TZ not working - mysql

We have a script to run through PHP myAdmin, as follows:
UPDATE utilities_alert SET date=CONVERT_TZ(date,'-06:00','00:00');
UPDATE utilities_update SET date=CONVERT_TZ(date,'-06:00','00:00');
UPDATE utilities_assetlocation SET start=CONVERT_TZ(start,'-06:00','00:00');
UPDATE utilities_assetlocation SET end=CONVERT_TZ(end,'-06:00','00:00');
UPDATE utilities_idlelog SET date=CONVERT_TZ(date,'-06:00','00:00');
It's not working and returning NULL values. Then I came across this
http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html
, followed all the steps and to no avail.

There may well be a bug in this verb, I spent some time getting very frustrated trying this. However I did get it to work if I used this format.
SELECT CONVERT_TZ(TimeSeen, 'America/New_York','Europe/London');
Where TimeSeen was a DateTime field.
If you have loaded the timezone data as you say, it should work.

The issue was that I forgot a + sign.
It should be:
UPDATE utilities_alert SET date=CONVERT_TZ(date,'-06:00','+00:00');
UPDATE utilities_update SET date=CONVERT_TZ(date,'-06:00','+00:00');
UPDATE utilities_assetlocation SET start=CONVERT_TZ(start,'-06:00','+00:00');
UPDATE utilities_assetlocation SET end=CONVERT_TZ(end,'-06:00','+00:00');
UPDATE utilities_idlelog SET date=CONVERT_TZ(date,'-06:00','+00:00');

Related

Wrong timestamp in MySQL

I make an insert using now() as default, and when i look in the table it says for example 11:00, and when i click on it, it specifies the timezone (+3:00). Which means that it equals 8:00 UTC+0. Which is WRONG, because I actually made that insert at 11:00 UTC+0.
More strangely, when I try "SET time_zone = '+9:00'" or no matter which timezone I specify, it doesn't change ANYTHING - now() still creates the wrong timestamp with with UTC+3.
If I just write a single query "SET time_zone = '+3:00'; SELECT now()", it returns the correct value.
But if I write "SET time_zone = '+3:00'; update table set time=now() where id=11", and then check the table, the problem appears again.
I'm using 000webhost.
Please help? It drives me insane.

SQL Update returning zero rows

UPDATE starfsfolk
SET starfsfolk.stada=2
WHERE starfsfolk.deild LIKE '%Hugbúnaðardeild%';
UPDATE starfsfolk
SET starfsfolk.stada=3
WHERE starfsfolk.deild LIKE '%Markaðsdeild%'
is prescisely the code i'm using.
i've tried various different versions of it(like = "Markaðsdeild" or LIKE "Markaðsdeild")
most of which work if i'm using select, but i needed to use update and its not working for some reason.
This WHERE command works on select but
it returns zero rows if i'm using the update command. What am i doing wrong?
Edit:
Just to clarify, stada is set to 1 in all cases before and after the update command. it hasn't changed from 1 to 2 and 3 like i wanted it to.
Edit2: heres a screenshot of the database, i could also give you the create commands.
Edit3: Stada is bit, not int, i found out, not sure what that changes tho.
Solution: Solved myself, since bit is just 1 and 0, the error was in the creation of the table so i remade it with stada as int and now the code is working.
If the value of stada is not changed by the query then zero rows will be returned because nothing was updated.
The character sets of the server and of the client are different.
http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html

Why is the use of #variable in this SQL statement not yielding results?

Hopefully a simple one, probably something silly that I've missed.
Why is the following statement not yielding any results:
SET #old_sites_path = 'sites/mysite.co.uk/', #sites_path = 'sites/default/'
-- Update the content within blocks
UPDATE `boxes`
SET `body` = REPLACE(`body`, #old_sites_path+'files', #sites_path+'files');
However if I simply substitute the variables in I get the result?
-- Update the content within blocks
UPDATE `boxes`
SET `body` = REPLACE(`body`, 'sites/mysite.co.uk/files', 'sites/default/files');
Just for background this is part of a larger script that helps me manage the deployment of Drupal databases.
Thanks :-)
Run this to get a clue:
SELECT 'sites/mysite.co.uk/' + 'files'
Then have a look at CONCAT().

mysql update statement path links adjustment

I got table smile need to update smilepath ( mass update ) im using this
UPDATE `smilie` SET `smiliepath` = 'http://newpathhere.com/smilies/smile.gif' WHERE `smilieid` =1;
ive to issues ,
need to mass update to all paths , i believe i can use where smileid > 1 not quite sure
2nd issue in old path its looks like http://oldpath.com/icons/smile.gif
so i need to replace only " http://oldpath.com/icons " and keep end file
any clue !
You can use mysql REPLACE function to do this:
UPDATE `smilie` SET `smiliepath` = REPLACE(smiliepath,' http://oldpath.com/icons/','http://newpathhere.com/smilies/') WHERE `smilieid` >1;

How to set mysql user variable when report loading Birt

Im using birt reporting tool since from year. its cool product very good.
Today i got a problem. that i want to set mysql user varible when report loading as a example SET #user="USR009";
I tried several ways to do this i couldnot get the answer could some one help me on this issue very thank full
im stuck on this problem
regards
roshan
You can set the value in the query using a report parameter, and initialize it in the script.
Add a report parameter (PARAMETER_1)
Add "SET #user = QUERY_PARAMETER;" before your select statement in your data set.
While the data set is selected, select the script tab and find the "beforeOpen" drop-down. In here, add a line: this.queryText = this.queryText.replace("QUERY_PARAMETER", params["PARAMETER_1"].value);
The script will replace all instances of QUERY_PARAMETER with the text. You might still need quotes around it in the set statement (i.e SET #user = "QUERY_PARAMETER";).
Problem Was resolved create a SP
delimiter //
Create PROCEDURE abcd(param INT)
BEGIN
SET #USER=param;
SELECT #USER;
END//
And in your query call the SP with varible;
works like charm