Is PHPmyadmin current date based on my computer's localdate? - mysql

I'm doing some testing for my system in selecting data between two dates.
so I tried changing my computer's localdate to like year 2020 and run my system, so I'm expecting my CURRENT_DATE is May 10, 2020.
and I wont be getting any rows from my query because all of my data is year 2018
But after I use my query of cur_date() its still selecting those 2018 rows.
so I thought maybe my Phpmyadmin has its own cur_date().
I'm doing this test for my system will be use for the next couple of years. so I want to try and test my queries if today is already 2025 or something.

I thought maybe my Phpmyadmin has its own cur_date().
PhpMyAdmin has nothing to do with it. Your local computer also has nothing to do with it.
When you put CURDATE() in a query, that's part of the query. It's just text, like the SELECT part or the FROM part.
That means it's evaluated by the MySQL server. Just like the data of your rows is retrieved from the server, not from PhpMyAdmin or your local computer.
So the date returned will be that of the MySQL server.
so I want to try and test my queries if today is already 2025 or something.
The way to do this is to take out the expression CURDATE(), and replace it with the "fake" date you wish to use instead.
Something like:
SELECT * FROM `TheTable` WHERE `TheDate` > '2025-01-01';

Related

SSIS ADO.NET Source - SQL Command Query Error

I have a problem where I try to read some data from QuickBooks Desktop file in SSIS through ADO.NET Source using QODBC driver. Driver is set up correctly, because I am able to preview table contents of the file like so
I am also successful in using SQL Command access mode when I do a simple query like SELECT * FROM Item.
But the moment I try to use SQL Command to incorporate a WHERE clause against TimeModified field like so: SELECT * FROM Item WHERE TimeModified >= '12/21/2022 1:16:34 PM' and try to preview I get an error saying this:
Now, I sent that row by using table access mode into a derived column and looked up what type TimeModified column uses and saw that it uses DBTIMESTAMP. So I suspected that you can't use the >= operator on that type, so what I also tried in my query is utilizing the DATE() function on the WHERE clause, omitting the time piece like so (Although ideally I would like to keep the hours to be able to use them in my query as time is important but for test sake):
But as you can see I got the Expected Lexical Element Not Found error.
I originally intended for this to work through an expression in which I obtain a value for a variable of most recent date by querying from a database prior this step and then get the items from the Item table that are older than said date. However, now I completely cut the expression idea just for the sake of trying to get this to work but it doesn't seem like it wants to. Am I doing something wrong? I made some querying in SQL against a date field by using strings of various formats like I showed earlier and those queries in SQL Server all succeeded but here nothing works.
If you are interested how the connection to QuickBooks Desktop is made I am using 32bit QODBC Driver which you can see there as 'QuickBooks Data' in the ADO.NET Source.
Thank you in advance for your help!
So I figured it out. Apparently with QODBC when it comes to timestamps you have to query them by doing something like this:
SELECT * FROM Item WHERE TimeModified >= {ts '2022-12-16 15:05:55.000'} ORDER BY TimeModified DESC
Here is some more info: https://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/2407/0/qodbc-desktop-troubleshooting-problems-with-date-format

MySql returns wrong time from table data

I have data in a table, and one of the columns is DATETIME.
select time from tbdt where unix_timestamp(time) > unix_timestamp(now()) order by time asc limit 1
now NodeJS prints wrong time in console.log() like,
actual datetime is 2018-12-16 15:00:00 in db table..
but mysql returns 2018-12-16T09:30:00.000Z
which is 5 hours 30 minutes difference and my time zone is +5:30 (IST)
I don't exactly know where it goes wrong, either in MySql or in Node Js
Need to use convert_tz function in MySql.
SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+5:30');
It has the following signature:
CONVERT_TZ(dt,from_tz,to_tz)
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_convert-tz
You should check the server time on which your MySQL is running as it will pick the time from the server on which it is hosted.
This is being done by the MySQL, not by NodeJS and you can verify the same by directly running your above query into the database by console or SQL developer tool.

Handle a different timezone in mysql

Long story short, I'm working on a server that has a different time zone to my local area, although the output should be relevant to this local area alone. I wrote a query to see if some record had been stored for 3 or more hours, and that works a treat, however, I'm trying to find a way to re-write it so that it can convert the time to this time zone, prior to comparing.
With my most recent attempt, it looks like it compares the time prior to converting the time, I was just wondering if there’s a way of doing it through mysql, I should probably also mention that I’m currently limited to using version 5.096. Below you can see what I’ve written so far, I only noticed there was a timezone issue once I actually uploaded a file onto my FTP and tested it through that.
If I’m doing something stupidly wrong, please tell me what I’m doing wrong exactly, and if you could provide a solution, it would be much appreciated! Thanks!
SELECT * FROM
(
SELECT *, IF(HOUR(TIMEDIFF(CONVERT_TZ(current_time, '-07:00', '+00:00'), Time)) >= 3, 1, 0) = 1 AS timing
FROM callLogs
WHERE Inqueue = '1'
ORDER BY Time, Inqueue ASC
) AS qry
WHERE qry.timing = '1'
Another thing I should probably point out, I can't use any stored procedures, I'm quite limited in terms of what I can do as it turns out, which is just great! I also tried to contact the hosting company that is being used, and they came back with nothing useful, I think their English is very broken. They weren't answering a simple question.... So... Any ideas? ¯_(ツ)_/¯
Make sure that timezone support is enabled by mysql:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
The system is your system timezone, the below query gives time difference between your system and GMT in seconds.
SELECT TIMESTAMPDIFF(
SECOND, TIMESTAMP('2018-02-01 00:00:00'),
CONVERT_TZ(TIMESTAMP('2018-02-01 00:00:00'), 'SYSTEM', 'GMT')
)

how i can get correct time using mysql?

For my website am working with phpmyadmin as a back end. i have number of queries written on mysql in my programs.
Queries are working fine.
> But the problem is i am getting previous date upto 12.30PM.
It is a problem with mysql server. It is delay with 12 hours 32 minutes according to my time.
To display today's date before 12:30 Pm, i have to change all code How i can solve this without changing.
its simple,just use now() method,its is a native mysql method, it will gives you correct time stamp.
guess you want to insert a time into table then use like
INSERT INTO X(time) VALUES (NOW());

How do I change the mysql server date using SQL

I need to change the server date via sql.
Preferably through my application (CL is also good).
How do I change the mysql server date using SQL?
Why:
We test a scenario that spans several weeks. To test it we need to advance the server date by that time.
Do you want to change the server date or the server timezone?
If it is the server date, you have to do it at the OS level.
If it is the time zone, you can change it globally for entire database instance or for your session/connection only.
The SET TIMESTAMP statement affects the value returned by NOW() but not by SYSDATE()