Output of Date in MariaDB - sql

Today I was using datagrip with the new view of MariaDB, and at executing
SELECT DATE('2018-03-01');
return '2018-02-28'. Meanwhile on MySQL view return the same Date that I put as String version.
I use MariaDB 10.1.26 with XAMP, Datagrip 2018.1.
It's the first time that make this.

Try use the CONVERT_TZ() because your problem is probably related to timezone, who are different their two instances (Maria and My), or update the timezone in the instances to be the same.
To check the timezone:
select ##system_time_zone;

Related

Oracle Apex - selecting date with different hours

We have a web application which we store a date from the user. The date is stored on an Oracle 19c database as a date field.
The problem we have is that when we select the date it's coming with different hours, like it's taking into account the timezone or something. So, for example one person can see the date 2021-05-20T13:00:00Z while another somewhere else can see 2021-05-20T12:00:00Z.
Is there a way to prevent this behavior, and have everybody get the same date and time?
Update
Most likely the problem resides in Oracle Apex, not Oracle database!
We use a very old version of Apex, 1.x it seems so maybe this problem doesn't happen on newer versions.
That is often problem when you use, for example, java.util.Timezone,java.sql.Date or java.util.Date type in java instead of oracle.sql.Date

Legacy SQL - How does this query compile?

I came across a surprising behaviour in Legacy SQL. Indeed, I launched this query by accident (I replace the '[[date]]' programmatically, I just forgot to replace it in UI) :
SELECT DATE(ComputationDate) as date
FROM [project:dataset.table]
WHERE DATE(ComputationDate) < '[[date]]'
ORDER BY date
And it worked ! I retrieved all data to today date. This fails in Standard SQL but was it an intended behaviour ?
It is not that much an issue but if my replacement fails, I cannot see it from code since the query still compiles.
Thanks
Below version (BigQuery Legacy SQL) will return no rows at all which can be good indicator for you that something went wrong
#legacySQL
SELECT DATE(ComputationDate) as date
FROM [project:dataset.table]
WHERE DATE(ComputationDate) < DATE('[[date]]')
ORDER BY date
The "culprit" is how it is cast under the hood. In my test, your query will return all the data for any string that cannot be parsed to a date type.

Teradata JDBC 16.20 returns wrong date in Datagrip

I am using Teradata JDBC 16.20 in Datagrip.
Whenever I try to do anything with date, it returns 1 day less.
For instance: SELECT date'2017-08-01' returns 2017-07-31 in Datagrip and in Teradata SQL Assistant it returns correctly 01/08/2017.
Does anyone know why?
We have the same issue using DataGrip with a Vertica database. My hunch is that the date is being shifted twice. When I select current_timestamp (which on Vertica is timestamp with timezone) the date is correct (typically one day earlier than the current date), but when I select current_date, I get the previous day (my timezone is US/Pacific). What I think is happening is the JDBC driver is adjusting the date based on the two timezones, and then DataGrip is then adjusting it a second time.
We don't have issues using the same Vertica database with the same JDBC driver, but a different SQL Client (DbVisualizer).
The only workaround I can offer using DataGrip is to install a much older version. DataGrip 2016.3.4, Build #DB-163.13906.13, built on February 21, 2017 seems to handle date columns correctly.
Adding -Duser.timezone=UTC to VM options seems to solve the problem.

Change Sqoop's Date Format in Incremental Import from SQL Server

TL;DR - Is it possible to change the date format Sqoop uses?
I am importing data from a SQL Server using Sqoop (version 1.4.6) and am specifying a datetime column as my --check-column.
Sqoop is querying the database using dates in the format yyyy-MM-ddd hh:mm:ss.SSS. However, since SQL server is configured to use British dmy date format, it, counterintuitively, interprets a date beginning with a year as having the day in the second position rather than the month (wtf?!).
E.g SELECT ... WHERE modified < '2017-01-31 00:00:00.000' is interpreted as selecting the data where modified is less than the 1st day of the 31st month 2017 which obviously throws an error.
Is it possible to change the date format Sqoop uses?
A quick scan of the Sqoop documentation did not reveal a way to change the date format. The Microsoft Support article here suggests that you could avoid the problem by issuing a
SET DATEFORMAT 'ymd'
statement immediately after opening the connection, but it appears that Sqoop only supports that sort of operation for Oracle (oraoop-site-template.xml) and not for other JDBC drivers.
There is an mssql-jdbc pull request that, if accepted, would let you add ;connectionDateformat=ymd to your Sqoop connection URL. In the meantime you may just have to change the default language of the SQL login for your Sqoop job from "British English" to (US) "English":

MS SQL 2005: Any way to temporarily set the system date for a T-SQL script to a different date?

We have a bunch of T-SQL scripts dependent on today's date and when they run. If one doesn't run on the week it should, we end up temporarily setting the system time a day before, run the script, then set it back.
Is there anyway to temporarily set the system date for a script without changing the original script, like when you execute it or only for that session?
You could store the actual date in a table / temp table.
THen retrieve or update that date rather then making a call to GetDate().
I've found an answer by someone else, here I share it: "The date is tied to the OS date and time. See here: http://msdn.microsoft.com/en-us/library/ms188383.aspx".
You could refer to this other question Simulate current date on a SQL Server instance?