snowflake timezone convert function is not converting - snowflake-cloud-data-platform

I am reading times from a snowflake DB in UTC/GMT, for example as
2021-12-14T18:11:32.753+00:00
2021-12-18T18:11:10.529+00:00
2021-12-20T00:02:02.781+00:00
I want to convert these to AEST(GMT+11), so I use the following statement:
convert_timezone('Australia/Melbourne', artifact_generated_at) as time2
But this seems to only convert the time zone component and doesn't actually convert the time.
2021-12-14T18:11:32.753+11:00
2021-12-18T18:11:10.529+11:00
2021-12-20T00:02:02.781+11:00
any thoughts? or should I be using a different function?

I used
CONVERT_TIMEZONE('UTC', 'Australia/Melbourne', artifact_generated_at)
which worked fine.

Related

Convert FileTime to DateTime in Azure Logic App

I'm pretty new to Logic App so still learning my way around custom expressions. One thing I cannot seem to figure out is how to convert a FileTime value to a DateTime value.
FileTime value example: 133197984000000000
I don't have a desired output format as long as Logic App can understand that this is a DateTime value and can be able to run before/after date logic.
To achieve your requirement, I have converted the Windows file Time to Unix File Time then converted to File time by add them as seconds to a default date 1970-01-01T00:00:00Z. Here is the Official documentation that I followed. Below is the expression that worked for me.
addSeconds('1970-01-01T00:00:00Z', div(sub(133197984000000000,116444736000000000),10000000))
Results:
This isn't likely to float your boat but the Advanced Data Operations connector can do it for you.
The unfortunate piece of the puzzle is that (at this stage) it doesn't just work as is but be rest assured that this functionality is coming.
Meaning, you need to do some trickery if you want to use it to do what you want.
By this I mean, if you use the Xml to Json operation, you can use the built in functions that come with the conversion to do it for you.
This is an example of what I mean ...
You can see that I have constructed some XML that is then passed into the Data parameter. That XML contains your Windows file time value.
I have then setup the Map Object to then take that value and use the built in ado function FromWindowsFileTime to convert it to a date time value.
The Primary Loop at Element is the XPath query that will make the selection to return the relevant values to loop over.
The result is this ...
Disclaimer: I should point out, this is due to drop in preview sometime in the middle of Jan 2023.
They have another operation in development that will allow you to do this a lot easier but for now, this is your easier and cheapest option.
This kind of thing is also available in the Transform and Expert operations but that's the next tier level of pricing.

How to convert token into a timestamp in SYSTEM$LAST_CHANGE_COMMIT_TIME in Snowflake

I am trying to get the last refresh date of table using a system function SYSTEM$LAST_CHANGE_COMMIT_TIME
select SYSTEM$LAST_CHANGE_COMMIT_TIME( 'table_name') -- returning a token
when I try
select to_timestamp_LTZ( SYSTEM$LAST_CHANGE_COMMIT_TIME( 'table_name')/1000) -- Invalid date
can anyone please help ?
TIA
You should note that the Snowflake documentation strongly discourages the use of the output of SYSTEM$LAST_CHANGE_COMMIT_TIME as a timestamp. Given that, …
The output of this function is epoch seconds so you just need to convert it to a timestamp e.g.
to_timestamp_LTZ( SYSTEM$LAST_CHANGE_COMMIT_TIME( 'table_name'))

How can I pass only the time using RadTimePicker in vb.net?

I am using a RadTimePicker which I want to be able to pass the time only to the database as it passes a date even when you don't set one.
How I want to pass it to the database:
10:30
How I want it to be stored in the database:
10:30
Error I received in Visual Studio:
"Cannot convert String to TimeSpan"
This was because of the RadTimePicker I am using automatically passes a date even if there isn't one set, so it passes 01/01/0001 00:00:00 and I don't need or want the date part.
Because I couldn't get it working I decided to do a workaround using varchar but then I was shown how to properly set it up using time datatype.
I used this for the conversion to fix my error I got the 1st time
Cast String to TimeSpan
The solution for that is shown below.
I have now corrected my answer to replicate the 'correct' way of storing time.
Input Fields:
How it's stored in the database:
Data Types in the 'Update DB stored procedure' and the database table:
Declaring global Date Variables
How to Pass only the time:
Passing Data using Dictionary
Hope this helps!

Snowflake variable data types

I am trying to declare a session variable to a date value but the variable keeps reading in as string or numeric.
I've tried setting the date with varying formats, with and without time, in utc format, etc but nothing has worked. All are seen as text unless i don't use quotes or apostrophe's, in which case 2019-09-01 results in 2009 number type.
set(myDate)='2019-09-01'
set(myDate)="2019-09-01"
set(myDate as date)='2019-09-01'
set(myDate)='2019-09-01 18:25:53.820000000Z'
no matter what i try when i run show variables it doesn't show as date or timestamp data type. if i run set(myDate)=current_timestamp() that works fine but I do not want the current date.
Finally figured it out so maybe this will help someone else. When setting the variable, use to_date to cast the value at the same time. e.g:
set(myDate)=to_date('2019-09-01');

Change SQL Server datetime/date format to dd/mm/yyyy

I'd like to change display format of all dates/datetimes among entire instance/database (whichever is possible).
I tried changing default language for the instance and for single users and it doesn't work. It always displays YYYY-MM-DD. Can this be changed without messing with the code to always include FORMAT function?
Use the following function and write the format you want
SELECT FORMAT(GetDate(), 'yyyy-MM-dd')

Resources