Google Data Studio Date Issue - google-bigquery

I'm trying to generate report from Google Data Studio where i am using BigQuery As Connector, i want to change my Time Zone As per My Location (Current Time and date) but not as per BigQuery Time zone,
is there any Chance do this in Google Data Studio.

You can use something like
DATE(timestamp,"Asia/Kolkata") as Timestamp
or
You can use Bigquery, the 2nd argument of the TIMESTAMP() function to convert UTC timestamp to your local time zone
SELECT TIMESTAMP("2020-02-24 13:30:00", "Asia/Kolkata") AS timestamp_in_IST;
Here is the supported timezone by Big query

The functionality (Time Zone calculations) is now available in Google Data Studio, with the introduction of additional Date Time functions in the 17 Sep 2020 Update. Using Mohit's example; where the goal is to convert the Date Time field (titled Date_Field in this Report) from the default (UTC) to Asia/Kolkata (change the Time Zone as required), the following does the trick:
0) Upgrade the Date Field
Ensure that the Date Time field has been upgraded to to the newer Date field type.
Added a GIF to elaborate:
1) Asia/Kolkata
PARSE_DATETIME(
"%s",
CAST(CAST(FORMAT_DATETIME("%s",DateField)AS NUMBER) - DATETIME_DIFF(CURRENT_DATETIME("UTC"),CURRENT_DATETIME("Asia/Kolkata"), SECOND)AS TEXT))
Google Data Studio Report and a GIF to elaborate:

Related

How to convert a UTC timestamp to a named timezone in SAP SQL Anywhere?

I'm using SAP SQL Anywhere 17 and have a timestamp (without time zone) which I know is UTC, and I know that my client's browser reports a time zone of "Europe/Berlin".
Is there an easy way to convert the UTC timestamp to a local timestamp of this time zone using SQL? Let's assume that I have already created the timezone with
CREATE TIME ZONE "Europe/Berlin" OFFSET '01:00' DST OFFSET '01:00' DST STARTING 'Mar/last Sun' AT '02:00' DST ENDING 'Oct/last Sun' AT '02:00';
I guess it is possible to do it manually using the SYSTIMEZONE view, but it is some hours of hard work to handle all the special cases! Maybe someone has done it already, or Anywhere provides a system function which I have overlooked in the docs.
Note that the problem is to find out whether DST is active at an arbitrary UTC timestamp. Using just the current offset will give wrong results if the timestamp is, for example, 6 months in the future!
When the timezone is activated on your server you have a connection property called TimeZoneAdjustment that returns the number of minutes relative to UTC. For Europe/Berlin this is "60" (during winter time/standard time).
You could add that offset manually using the DATEADD function:
SELECT CURRENT UTC TIMESTAMP AS my_utc_timestamp,
DATEADD(minute, CONNECTION_PROPERTY('TimeZoneAdjustment'), my_utc_timestamp) AS localtime
Newer versions of SQL Anywhere 17 have a new function TOLOCALDATE that automatically applies the current connection's offset to an UTC timestamp (although I couldn't test that function cause my version is to old).

What kind of a timestamp is this?

We are extracting data from a third-party database for export. Two of the columns are Timestamp columns with some of the values displayed below. The timestamp is supposed to represent a UTC timestamp from a GPS device. They are stored as int data types in an SQL Server database.
Any idea how I can convert this timestamp (e.g. 368815303) to a regular date/time? The numbers seen should be very recent - i.e. within Sept 2020 and should represent the time down to the nearest second.
Based on the comment, you would use:
select dateadd(second, 368815303, '1980-01-06')
Based on your expectation, the base time appears to be about 2009-01-01, which suggests:
select dateadd(second, 368815303, '2009-01-01')
I am not familiar with any date/time epoch that uses that as the base time. It might be some bespoke system.
It looks like some kind of epoch Unix timestamp.
Try this Epoch Converter which converts timestamp to human date

Data displayed with a time-shift, not the original time

I just started using Grafana and I am new to SQL as well. I posted this on Grafana community as well, but got no response yet. I set up a simple dashboard with timescaleDB for grafana and the time data was added in the Postgres database as "timestamp without timezone" (e.g:- in the format of '2020-04-27 22:38:36' etc.) In the dashboard, data does not get displayed for the current time while the DB being updated/data does not get displayed for the actual time data was written to the database but displayed with a time shift, when actual data was written at 11.mm.ss they are displayed for 17.mm.ss on the graph. (as here - dashboard picture) (below is the query I make to get the output result shown in the image (I have only written data to the database for an interval of time))
SELECT
"time" AS "time",
score
FROM scoredata
WHERE
"time" BETWEEN '2020-04-27T11:20:35.925Z' AND '2020-04-27T12:20:35.925Z'
ORDER BY 1
I have tried changing the timezone from the dashboard setting as well. But gave no change to the result.
Officially the time column must be in UTC time to be diplayed correct. If this is not the case, you can convert it. I have a PostgreSQL database with local time. To use it correctly in Grafana, I use
$__timeGroupAlias(time at TIME zone 'Europe/Berlin' at TIME zone 'UTC',$__interval,0),
with time as the name of the time column. In the time filter the same has to be done
WHERE
$__timeFilter(time at TIME zone 'Europe/Berlin' at TIME zone 'UTC')
Credits to How to convert local time to UTC?
I got the answer from the Grafana community page. The data needed to be stored in UTC in the database. Grafana will convert them to the local time.

How to show date/time in local time zone in Data Studio from UTC timestamp in Big Query

I want Google Data Studio reports to show sales data (including a sales-by-hour heat map report) using the user's local time zone. I'm storing the data in BigQuery and the timestamp field is stored as UTC.
Per Data Studio Help, it sounds like the timestamp should be stored as UTC (which I'm doing). I assumed Data Studio was smart enough to convert UTC to the user's local time zone, but that doesn't appear to be the case.
Everything is working perfectly except the hours on the heat map report show as 8:00-17:00 instead of 12:00-21:00. It's showing UTC instead of EST (my time zone), and I cannot figure out how to fix this.
Does Data Studio automatically adjust the report data based on the user's time zone? If so, what am I doing wrong? If not, are there any workarounds that would support users from multiple time zones?
The 17 Sep 2020 Update to Google Data Studio introduced updates to Dates and Times as well as new functions and ways to works with Dates and Times which includes Time Zones.
0) Upgrade the Date Field
Ensure that the Date Time field has been upgraded to to the newer Date Time field type.
Added a GIF to elaborate:
1) EST
This Calculated Field obtains the difference in SECOND between UTC and EST by using the DATETIME_DIFF function, and subsequently subtracts the difference with the Date Time field (called DateTimeField in this Report):
PARSE_DATETIME(
"%s",
CAST(CAST(FORMAT_DATETIME("%s",DateTimeField)AS NUMBER) - DATETIME_DIFF(CURRENT_DATETIME("UTC"),CURRENT_DATETIME("EST"), SECOND)AS TEXT))
Google Data Studio Report and a GIF to elaborate:
You can use the second argument of the TIMESTAMP() function to convert the UTC timestamp to a specific time zone. Here's a list of time zones supported by Big Query.
ex. SELECT TIMESTAMP("2008-12-25 15:30:00", "America/New_York") AS timestamp_in_est;
+-------------------------+
| timestamp_in_est |
+-------------------------+
| 2008-12-25 20:30:00 UTC |
+-------------------------+
Data Studio does not adjust timestamps based on timezones. All timestamps are displayed in UTC unless specified.
In my case the solution was convert the time to MICRO and then add 1 hour(MICRO).
TODATE(((name_of_column)+(3600000000)),'MICROS','%Y%m%d%H%M')

How to return correct local time in Postgres

select current_time at time zone 'GMT-2'
returns
"11:54:40.22045+02"
but correct local time in Windows is one hour different:
12:54
How to get correct local time ?
Using
"PostgreSQL 9.6.0, compiled by Visual C++ build 1800, 32-bit"
with standard postgresql.conf file in Windows 10
Same issue occurs also in ealier Postgres and in earlier windows.
Server time in Windows is correct.
Daylight saving time was changed by one hour a week ago.
Maybe postgres didnt recognized it.
Don't use time with time zone, it is a useless data type.
See the documentation:
The type time with time zone is defined by the SQL standard, but the
definition exhibits properties which lead to questionable usefulness.
In most cases, a combination of date, time, timestamp without time zone,
and timestamp with time zone should provide a complete range of date/time
functionality required by any application.
Use localtime to get the current time at your current session time zone (defined by the TimeZone parameter).