I receive dates as a strings for period 30 october to 31 october when daylight saving is happening.
Relevant data:
[
["2022-10-30T00:00:00+02:00",103.01],
["2022-10-30T00:15:00+02:00",103.01],
["2022-10-30T00:30:00+02:00",103.01],
["2022-10-30T00:45:00+02:00",103.01],
["2022-10-30T01:00:00+02:00",100.49],
["2022-10-30T01:15:00+02:00",100.49],
["2022-10-30T01:30:00+02:00",100.49],
["2022-10-30T01:45:00+02:00",100.49],
["2022-10-30T02:00:00+02:00",100.2],
["2022-10-30T02:15:00+02:00",100.2],
["2022-10-30T02:30:00+02:00",100.2],
["2022-10-30T02:45:00+02:00",100.2],
["2022-10-30T02:00:00+01:00",99.92],
["2022-10-30T02:15:00+01:00",99.92],
["2022-10-30T02:30:00+01:00",99.92]
]
At 2AM they are multiple values but different GMT
I convert the strings to ZoneDateTime with this line:
val zonedTimestamp = ZonedDateTime.parse(timestamp)
.withZoneSameInstant(ZoneId.of("GMT"))
And the values seems to be ok, they are all consecutive, no duplicates for that 1 hour, no GMT added to them
The field timestamp on entity is unique and is of type ZonedDateTime.
In mariadb the field is declared as timestamp (i have used also datetime but is the same problem).
And on saving of the entities i receive the error Duplicate entry '2022-10-30 03:00:00' for key 'timestamp', somehow mariadb is not taking those ZonedDateTime as their values.
I saw suggestions to use timestamp with time zone but is not such a thing in mariadb.
Related
I have a particular table in mysql with a field refresh_time Type as timestamp.
In my code, I update the refresh_time field to a future date of next month. For that, I calculate the milliseconds for next month date using following logic :
periodRefresh = currentTime + MyServiceUtils.calculateNoOfDaysInMonth(currentTime)*86400000L;
And then the value periodRefresh (milliseconds) I convert to java.sql.Timestamp and pass it to db side to udpate the field :
new Timestamp(periodRefresh);
But what has happened was that the current date in db was 2021-04-03 15:57:13 and when the above logic was run to update the time to next month, same time, it updated the time as 2021-05-03 13:57:13 which is 2 hours less than expected.
Our server follows UTC timezone, but I see that the user was from Australia, and in that day (4th April 2021) there was a daylight savings time in AEST. But even then it doesn't add to above as if I convert 2021-04-03 15:57:13 UTC to AEST, it comes as 2021-04-03 01:57:13 and the daylight savings there is at 3 am.
All the above has confused me a bit with following questions:
If I am following UTC timezones, then also does sql.Timestamp and mysql can get affected by daylight saving time?
How is AEST daylight saving time affecting my Australia based user when I follow UTC timezone?
Even if DST was affecting, so it should have increased/decreased time by 1 hour, but how in my case a difference of 2 hours happened?
In MySQL, TIMESTAMP datatypes are always stored in tables as UTC. When you put them into the database, it first translates them from your connection's time_zone setting to UTC. And when you retrieve them it translates them the other way. This is not true of DATETIME data types.
This TIMESTAMP behavior is handy if you have a global app. You can ask each user for their preferred time zone, and store it as a user-preference setting.
If you take a raw (seconds since the UNIX epoch in UTC) TIMESTAMP value and add a month's worth of seconds to it, the resulting timestamp value may be in a different daylight-time regime. So it will be translated differently.
Either
do your timestamp processing in MySQL, for example with
UPDATE tbl SET periodRefresh = periodRefresh + INTERVAL 1 MONTH;
do it all in your app and use DATETIME, not TIMESTAMP, data types (to avoid the database's time zone translation, or
do it all in your app and use SET time_zone='UTC'; on every connection.
I've took the Date as the datatype and inserted one record in mongoDB. It is inserted as 2020-04-23T13:41:37.410+00:00 but the current time is 2020-02-23 19:22 (IST). Even if the database in the local also it is inserting the same time.
Please help me with this
MongoDB stores times in UTC by default, and will convert any local time representations into this form.
Below is my system current time
print(new Date() );
Thu Apr 23 2020 19:29:51 GMT+0530 (India Standard Time)
But when I save this in a collection, it will be saved as UTC (ISO date), though it printed new Date in step 1 as IST
db.getCollection("Demo").insert({dat:new Date()})
db.getCollection("Demo").find({})
{ "_id" : ObjectId("5ea1a0d53cd3ffdd3bef987c"), "dat" : ISODate("2020-04-23T14:06:12.564Z") }
First, that's 5.5 hours (not 6.5 hours). And, +00:00 means it is being stored in UTC (not in your local time). The IST offset is
UTC+05:30.
I need to create a query with my local time (+07:00). The server time is in GMT and all times stored in DB are in GMT too.
For example, today is June 18 I want to find records whose created_at (type: Date) is yesterday in my local time, which means the start date should be 2019-06-16 17:00:00.000 and the end date should be 2019-06-17 16:59:59.999. Is it possible to pass the timezone?
Trying to fix a bug in our reporting. Currently the issue is as stands:
At 9:45PM on 2/22 in PST someone submits a work order.
It hits our Oracle Database and normalizes to EST (our db is in EST, but we work with clients all over US).
In iReport, we are using the following:
trunc(nvl(ls.date_occurred,ls.date_created)) between TRUNC($P{DATE_FROM}) AND TRUNC($P{DATE_TO})
This STRIPS the timestamp off of the datetime object, so when the report is generated it does not save the hours, only the date which is now 2/23 (at 12:25 AM respectively).
This obviously throws off our reporting feature. All of the data seems to be correct except this date offset that is generated a day after because of the timezone difference, and the adjusted data not having a timestamp asociated with it.
Does anyone have another way to adjust for datetime without using a function that strips the timestamp off of the date?
As I understand your from/to dates are not in EST which makes the discrepancy between the dates you require in your report to the date in you Database. In order to get the correct records instead if truncating the dates you need to adjust the requested to/from dates according to the timezone of the request (If you request from PST timezone first convert the dates to EST then make the query)
also, you can look at : TIMESTAMP WITH TIME ZONE Datatype
https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm
Turns out that I need to adjust for the timezone of date_created inside the nvl, because date_occurred is trunced whereas date_created is not. This causes data loss.
I have date(01-oct-2014), time (00:37:31), GMT difference(-360) now
I want to get the time conveted to CST. The solution can be in javascript
Or oracle databse.
I have read several articles but could'nt get any where..can some one help me out on this...
In Oracle, to convert your local time to time of another timezone, you need to CAST TIMESTAMP WITH TIMEZONE.
For example, I want to convert 'IST' Indian standard time, i.e. my local timezone to 'CST', i.e. Central :
SQL> WITH T AS
2 ( SELECT to_timestamp('10/01/2014 11','mm/dd/yyyy hh24') ist FROM dual
3 )
4 SELECT ist,
5 CAST(CAST(ist AS TIMESTAMP WITH TIME ZONE) at TIME zone 'CST' AS TIMESTAMP) cst
6 FROM t
7 /
IST CST
----------------------------------- ------------------------------
01-OCT-14 11.00.00.000000000 AM 01-OCT-14 12.30.00.000000 AM
Take care of Daylight saving. You might have to take care in understanding CST and CDT.
There are several ways to do this:
SELECT
(TIMESTAMP '2014-10-01 00:37:31') AT TIME ZONE 'CST',
FROM_TZ((TIMESTAMP '2014-10-01 00:37:31'), 'CST'),
CAST((TIMESTAMP '2014-10-01 00:37:31') AT TIME ZONE 'CST' AS TIMESTAMP)
FROM DUAL;
It depends if the result shall include the new time zone or not.