Wrong timestamp in MySQL - 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.

Related

Selecting a checkbox in mySQL DB

I ran a sql query in an effort to update a column for a specific user who listed bunch of products that were set to expire.
When I look at the phpmyadmin db, all of the products had end_time filled with zeros thanks to my wrong sql query shown below.
UPDATE my_listing SET end_time='NULL' WHERE user_id='3'
What I needed was to check the "Null" checkbox in end_time, to ensure unlimited duration, the zeros did the opposite and made all products 'expired'.
How do I set the "Null" checkbox checked without going manually and doing it by hand?
Thanks much!
Just run another query, this time setting end_time to NULL instead of the string 'NULL':
UPDATE my_listing SET end_time = NULL WHERE user_id = '3'
The checkbox of phpmyadmin has no effect on the column value, but only sets if it can be set to NULL. Therefore after having checked it you should simply run again the query like that:
UPDATE my_listing SET end_time=NULL WHERE user_id='3'
without the ' ' around NULL.

Change timestamp in mysql

I lived in philippines and when I'm inserting date in my database, It's inserting less 13 hours in my database. For example, our datetime here is 02-11-2016 21-04-00, when I insert, it's inserting 02-11-2016 08-04-00
I already used this:
date_default_timezone_set('Asia/Manila');
But no luck. I already put the website in my domain.
This should be done by
date_default_timezone_set('Asia/Manila');
Make sure you are uploading the correct files.
If it doesn't work; try making a page for error handling, then echo a variable that will set the time for this timezone, if it works. Use that variable instead.
The timezone you set is used for PHP as Bimal said, you need to check the server time as well, because time is very sensitive part of the information you don't want to miss or play with.
I've been in that situation couple of weeks back, there are two ways to fix it:
Set the server timezone to the correct timezone.
If the time difference is always and EXACTLY 13 hours, use this approach:
$new_time = date("Y-m-d H:i:s", strtotime('+13 hours')).
I ended up using the second method as the first one was not an option for me.
Best of Luck.
If I am not wrong you have pasted php function which will just set time_zone for php not for my_sql. mysql has global time_zone variable which can be set. You should use SET GLOBAL time_zone = timezone; or SET time_zone = timezone;.
If you dont have direct control of your DB server in that case you can pass the 2nd statement i.e set time_zone=...; as 1st statement.
Alternatively you can also use the convert_tz function to convert an already stored value.

How to change curtime?

How to change curtime value in MySQL, I run query SELECT CURTIME() and the result is 18:49:12.
I want to change the value to 17:49:12
If anyone knows a good way to do this I'd very much appreciate your help.
CURTIME() value is a value based on server timezone. You can change server timezone:
SET time_zone = 'America/New_York';
Or do this with MySQL function ADD_DATE():
SELECT SELECT DATE_SUB(CURDATE(), INTERVAL 1 HOUR)
You could be set the time-zone manually, like so:
SET GLOBAL time_zone = '-1:00';
or to set to your system time:
SET GLOBAL time_zone = SYSTEM;
See the documentation for more information.
Hum, I don't think you can do this. It would imply that mysql can change the system time !
If you are trying to get a different time zone, you could apply timezone OR if u always want to get 1 hour before current time you could reduce the current time by 1 hour

mysql server_time_zone or time_zone

am trying to change the time of my sql server:
serve_time_zone=GMT Daylight Time
time_zone=SYSTEM
i have tried:
SET TIME_ZONE='+01:00';
to get the correct time_zone, but when i restart server to take effect it resets itself.
i have searched and not found anything which will not reset itself. I have now downloaded Hiedi SQL to view my database.
I want to advance the time of the database by 1 hour 1+GMT
Have you tried this: SET GLOBAL time_zone = timezone;??

Overcoming timezone differences in MySQL Select

I am trying to select entries for a current date but cannot seem to get past the issue of a 1 hour time difference between my timezone and that of the server.
I was able to overcome this by using DATE_ADD() for adding entries but now I need to do the same to SELECT them. I tried inserting SET time_zone = 'America/New_York'into my MySQL connection command but it did not appear to change anything. I am using a PDO::QUERY statement, here is my connection command:
$db = new PDO('mysql:host=localhost;dbname=nightdes_points', $dbuser, $dbpsw);
What am I missing here? Thanks!
I would always store data in GMT0 and on insert/update/select I would always pass (converted) GMT0 date.