Reputation: 33
I am using SAP HANA and I need to do some things with dates (add days mainly).
I am having a problem working with a particular day of the year, the 2nd Saturday of May. My guess is that this is related to daylight saving.
I simplify the query to show the problem.
DO
BEGIN
DECLARE FECHA VARCHAR(20) = '2020-05-10';
SELECT :FECHA AS D1
, TO_DATE(:FECHA) AS D2
, TO_VARCHAR(TO_DATE(:FECHA)) AS D3
FROM DUMMY;
END;
What I get as a result is this:
|------------|-------------|------------------------|------------|
| D1 | D2 | D3 | D4 |
|------------|-------------|------------------------|------------|
| 2020-05-10 | 09-may-2020 | 09-may-2020 23:00:00.0 | 2020-05-10 |
|------------|-------------|------------------------|------------|
This causes all sorts of problems when adding days which is what I am encountering. But just this simple example shows more than enough.
Thanks in advance for your suggestions.
Upvotes: 2
Views: 1241
Reputation: 10388
Mikel Rychliski is nearly correct with his answer.
As I explained in the blog post Trouble with time? a few years ago, SAP HANA Studio is a JAVA application that uses java.sql.Date
/java.sql.Timestamp
objects to handle date/timestamp information. And to use those, a Calendar
has to be configured.
Without further configuration (i.e. the mentioned JVM parameter -Duser.timezone
) the JVM uses its default timezone setting.
To quote from my post:
If the JVM runs on Linux, that would be the value of TZ again, on MS Windows it would be the current timezone setting for the Windows user that runs the JVM.
If you want to convince yourself that the data in SAP HANA is correct, using a non-JDBC based connection is an easy way to do so.
For example, just run your code via hdbsql
or an ODBC client.
Upvotes: 1
Reputation: 3607
HANA Studio (and all other JDBC applications) assume that DATE
's stored in the database are UTC. These values are converted to the local timezone of the client when they are fetched.
In your own JDBC application, you could pass a Calendar object on the getDate() call to specify which timezone you would like the server value converted to.
HANA Studio depends on the JVM timezone setting, which by default is read from the OS. To avoid this issue in HANA Studio you can add the JVM property -Duser.timezone=UTC
in the hdbstudio.ini file (or change the timezone on you machine).
Upvotes: 0
Reputation: 33
I think the problem is with Hana Studio since in DBeave it works as expected :P I am leaving this question here in case someone else needs to know how to fix this.
I will try to find a way to fix it in Hana Studio and post back.
Upvotes: 0