MySQL says 'SYSDATETIME' does not exist - mysql

I am trying to select rows from a table where the date column value is equal to the current date in Sydney, Australia (UTC+10h). The server is based in Sydney, and so I would like to use SYSDATETIME(). This is my query:
SELECT * FROM database WHERE DATE(date) = DATE(SYSDATETIME())
But this returns the error:
1305 - FUNCTION database.SYSDATETIME does not exist
What am I doing wrong?
EDIT: I used this documentation

As the error message suggests, there is no such function as SYSDATETIME in MySQL. The documentation you are referring to is for Microsoft SQL Server.
The function you are looking for is simply called NOW().

You have to use SYSDATE instead of SYSDATETIME.
The SYSDATE function will return the current date as a 'YYYY-MM-DD HH:MM:SS' format.

Related

Grafana dashboard using MySQL: how should I deal with timestamp of "%Y%m%d%H%i%s" to use as time column of panel?

I want to visualize my MySQL DB table to an hourly basis graph using Grafana dashboard. The table that I'm working with has the attributes below, with unused ones including PK not mentioned:
SERVER_NAME varchar(250)
STAT_TYPE int(11)
STAT_DTM varchar(14)
CPU_MAX_USAGE int(11)
MEMORY_MAX_USAGE int(11)
What matters is STAT_DTM. Its format is "%Y%m%d%H%i%s", e.g. "20210621090000"; for 09:00:00 of June 21st 2021. I want this to be the X axis of the graph. Grafana guide says:
return column named time or time_sec (in UTC), as a unix time stamp or
any sql native date data type. You can use the macros below.
So I put unix_timestamp(date_format(str_to_date(substr(stat_dtm, 1, 10),'%Y%m%d%H'), '%Y-%m-%d %H:00:00')) but an error saying db query error: query failed - please inspect Grafana server log for details popped up.
select
unix_timestamp(date_format(str_to_date(substr(stat_dtm, 1, 10),'%Y%m%d%H'), '%Y-%m-%d %H:00:00')) as 'time',
CPU_MAX_USAGE,
MEMORY_MAX_USAGE
from lcop.tb_stat_os_day
where stat_type = 60 and server_name = 'LDFSWAS1'
The Panel I'm currently working on
The result of the query above
How can I set the timestamp correctly and show the graph? The table schema cannot be modified unfortunately and I can give any additional info if needed. Thanks in advance.
Let's simplify your type conversion there:
SELECT '20210621090000' as `src`,
UNIX_TIMESTAMP(STR_TO_DATE('20210621090000', '%Y%m%d%H%i%s')) as `dts`
The STR_TO_DATE() function can be given the full format, which can then be given to UNIX_TIMESTAMP. There is no need to make things more difficult with SUBSTR() or DATE_FORMAT() 👍🏻

What is the current date in New York?

How do I fix this query to select the current date, in YYYY-MM-DD format, in New York?
SELECT CURDATE(); // sometimes returns the current date in New York, sometimes does not
My reporting software does not allow me to use SET or other statements or configuration options. I can only execute a single SELECT query. Is it possible to get the correct answer in the format above?
select date(convert_tz(now(), ##time_zone, 'America/New_York'))
but verify that the mysql server has timezone information installed by doing:
select * from mysql.time_zone_name where Name='America/New_York';

SQL Query nvarchar to date

I am working on SAP HANA Studio and have tried to run SQL command that converts an entire column of field, nvarchar, into one of field, date.
My dates have format: dd-mon-yyyy (i.e '29-Mar-1997') with field nvarchar(11).
I have looked at previous questions and SQL command documentation (for functions like CAST, CONVERT, TO_DATE, STR_TO_DATE) and have not gotten a solution.
Typical errors I get are: Function not recognized, or, Error while parsing Service Date as DATE at function to_date().
Any suggestions?
Thanks
-Diana
Try TO_DATE():
select to_date(col, 'DD-MON-YYYY')
Obviously your database driver/layer in SAP HANA does not support all mySQL functions.
Please connect to your database directly (using command-line or a gui like HeidiSQL) and create a view in your database:
CREATE VIEW view_tablename AS
SELECT STR_TO_DATE(`Service Date`, '%d-%b-%Y') AS ServiceDateDt, * FROM tablename
Then use view_tablename instead of tablename in all your queries - because view_tablename has the additional date field "ServiceDateDt".

Find output of MySQL inbuilt function in CLI using custom parameter

I want to see the working of MySQL functions FROM_UNIXTIME() and UNIX_TIMESTAMP() by providing the parameters to them myself in CLI, something like this:
SELECT UNIX_TIMESTAMP(1459460268);
without having to insert these custom values in a table first and then selecting them to see the output.
Thank you for your time :)
UNIX_TIMESTAMP function accepts a date and you are giving it UNIX TIMESTAMP. You can simply run this in MySQL CLI and get the results:
SELECT UNIX_TIMESTAMP("2016-04-01 03:07:48");
SELECT FROM_UNIXTIME(1459460268);
SELECT UNIX_TIMESTAMP();
The last one will return you the current UNIX TIMESTAMP.
Happy coding!

MONTH IN MS ACCESS

When executing the code , Datatype mismatch Error is showing .Can tell if i need only Month(either as January,February.. or as 1 ,2,...12) as a field in MS Access database what should i give as data type.
Thanks for your answer.One more query:
if (rs6("TotalDays")+ tdays) > rs5("Sing") then
Is there any syntax error in this statement..?
tdays holds the number.
Month() in access takes a parameter of type DateTime and returns the number of the month. To get the month name, you could either do FormatDate(Month(yourDate), 'mmmm') or MontName(yourDate) (in Access 2000 and later).
See here for more info.