Converting UTC 0 to UTC local in SQL. But for two different time zone - sql

I want historic date convert UTC 0 to UTC local in SQL. Like;
2012-11-23
2013-01-08
2014-02-23
But we have 2 different time zone. We use UTC +2 after last sunday in March and use UTC +3 after last sunday October. I need solution immediately guys. Please help me...

Try this:
SELECT CONVERT_TZ('your date ','+your time zone','+time zone you want');
SELECT CONVERT_TZ('2004-01-01 12:00:00','+02:00' ,'+03:00'); // in your case, from +2 to +3
See this link
If you need a dynamic thing, you'll need the timezone of each history (maybe you can store it in a separeted column), so I think you can do something like this:
SELECT CONVERT_TZ('your_date_column','local_timezone' ,'time_zone_column');

Related

timestamp difference in bigquery with date

I have used Dataiku to transfer 40 GB of data from snowflake to big query. Somehow timestamp value changed my dates completely
Instead of 2021-06-30 00:00:00 UTC the copied timestamp value is 2021-06-29 22:00:00 UTC
I am looking for a bigquery solution to cast this into the correct timestamp as loading the data again is not possible.
Can someone help please? Thanks
found the solution
SELECT TIMESTAMP_ADD(Day_Sts, INTERVAL 120 MINUTE) AS Day_Sts,* except (Day_Sts)

parse_timestamp vs format_timestamp bigquery

Could someone help me understand why these two queries are returning different results in bigquery?
select FORMAT_TIMESTAMP('%F %H:%M:%E*S', "2018-10-01 00:00:00" , 'Europe/London')
returns 2018-10-01 01:00:00
select PARSE_TIMESTAMP('%F %H:%M:%E*S', "2018-10-0100:00:00", "Europe/London")
returns 2018-09-30 23:00:00 UTC
As 2018-10-01 is during british summer time (UTC +1), I would've expected both queries to return 2018-09-30 23:00:00 UTC
The first is given a timestamp which is in UTC. It then converts it to the corresponding time in Europe/London. The return value is a string representing the time in the local timezone.
The second takes a string representation and returns a UTC timestamp. The representation is assumed to be in Europe/London.
So, the two functions are going in different directions, one from UTC to the local time and the other from the local time to UTC.

today's date filter showing next day data in table chart

When i select date as sept 16,i get to see sept 16 6am and sept 17 data until 5:59 AM.
It is treating 24 hours from sept 16 am to sept 17 6am.
Is there any issue with date field or report filter issue?
BigQuery's date functions work based on UTC timezone.
The UI you are using probably converts them into your local timezone, and you are seeing the 6 hours difference.
For visibility purposes I am posting my comment as an answer:
As #Pentium10 mentioned:
BigQuery's date functions work based on UTC timezone. The UI you are using probably converts them into your local timezone, and you are seeing the 6 hours difference.
According to this Data Studio uses UTC standard time, but if your data set does not use UTC you can use the TODATE function to convert the date field to UTC.

Extract date,month,year and month name from the unix timestamp with postgresql

I use postgres for the rails app and I have a unix timestamp in postgresql db. I have a requirement to select and group by the dd-mm-yyyy and by month name.
Consider I have the following unix timestamp
1425148200
and I would need to change this to datetime and I used to_timestamp which returned
2015-02-28 18:30:00 UTC
and I tried to convert the datetime to local timezone using
::timestamp without time zone AT TIME ZONE 'IST'
but that did not give time in required timezone and instead it returned
2015-02-28 16:30:00 UTC
and I tried to get the date part using ::date which returned
Sat, 28 Feb 2015
So please help me get the dd-mm-yyyy in specified timezone and month name(March) from the unix timestamp.
Thanks in Advance!
select to_char(to_timestamp('1425148200')::timestamptz at time zone 'UTC-5:30','DD-MM-YYYY & of course Month')
01-03-2015 & of course March
It is postgres mistake I guess
according to http://www.postgresql.org/docs/7.2/static/timezones.html

Default implied time for comparison in Oracle SQL TO_DATE?

I'm doing a SQL query in Oracle 10g where I'm comparing against a cutoff date. So my query has this in it:
THING < TO_DATE('02/14/13','MM/DD/YY')
Now the THING can have a time component in it. I want to know how the cutoff date will interact with it. Does the TO_DATE function have some default implied time component in it? Does the date it creates have a default time of midnight on the specified date, or noon or some other time? Essentially my concern is if I have a column in the table like this:
THING
-------
2/4/13 11:13AM
2/13/13 3:36PM
2/14/13 2:00PM
2/15/13 1:52AM
Will I get 2 rows or 3 rows back?
The implied time is 00:00:00, so in your example you will get two rows back.
You can verify this with:
select to_char(TO_DATE('02/14/13','MM/DD/YY'),'YYYY-MM-DD HH24:MI:SS')
from dual;
You'll get two rows back. The implied time is 0:00:00 (midnight). Your dates with a 24-hour clock look like this:
2/13/13 3:36PM --> 2013-02-13 15:36:00
TO_DATE('02/14/13','MM/DD/YY') --> 2013-02-13 00:00:00