Yet another SQL timestamp doubt

shubhamnodered
Fri, 27 Sep 2024 10:59:50 +0000
General

Hi Guys and Hello node red team,

My query is in reference to the point that Julius @TotallyInformation mentioned = "Always store DB entries in UTC" in the article " Wrong Timezone data in sql query result?!?"

I found that its two ways to achieve this:

1. Client side conversion - (Doing conversion in node-red & feed that into SQL)

2. Server side conversion - (By using SET GLOBAL time-zone = '+00:00')

And as per GPT, first one is more preferrable.

Let's discuss client side approach:

Issue - Let's say, i am working in IST(UTC+05:30) and current time is 15:00:00 then this timestamp(converted to UTC in nodered) pushed into SQL & is logged as +09:30:00 (UTC). Now, when i read this value back into node-red, this get value further subtracted by 05:30hr, and so the current time is reading as '04:00:00'.

Now, there is two way to address this issue:
a. Either using CONVERT_TZ(timestamp, '+00:00', '+11:00') in func node
b. Or, By setting MySQL database's timezone in MySQL node to +05:30(IST).

The thing is:

1. The 2nd approach that i mentioned above is not giving desirable result (which it should) because i am categorically mentioning the timezone of SQL server. Because by setting it as +05:30, it push back reading by 11:00hrs from actual time. So, what exactly is happening here? [note- but if i set it as -05:30, node-red displays SQL time correctly! ]

2. @TotallyInformation @E1cid as already mentioned that node-red converts current local time into ISO 8061 UTC format which is true, But what if i/p data is already in UTC format(as in my case as i'm importing UTC time data from SQL)? Why it cannot able to categorize it as UTC and goes on to further subtract it by 05:30 hrs showing actual time lagging by 11:00hrs?

Also, MySQL time-zone is 'SYSTEM' which is 'UTC+05:30'

Hope, i made myself clear. Please, help me understand this...

Regards,

18 posts - 6 participants