Skip to content
Advertisement

Tag: datetime

Create an array in Snowflake

I want to create an array constructed from two timestamps. After that, use this as a range to find the difference between the first element and the second element. The goal is to find the time difference between timestamps within business hours (9 am to 17 pm). What should be the right approach here? Can I create arrays and then

Set minutes of timestamp to a specific value

What is the easiest way to set the exact minutes value of a timestamp? This only adds minutes instead of setting the exact value: Answer Use date_trunc() before you add 2 minutes: Or, to retain seconds and sub-seconds: Demo: Should be substantially faster than manipulating the text representation and casting back.

SQL date scenario for getting previous month’s data to-date on the 1st of month, then drop last month

I’m trying to recreate an existing View in Snowflake (originally in SQL Server). I need to get last month’s data which is easy enough, but here’s the scenario: On 3-1-21, it should retrieve 2-1-21 to 3-1-21, but then starting on 3-2-21, it should only show 3-1-21 to-date, as our month end reporting goes out on the 1st of the month,

How to read from the two same dates without input the time

I have a query like below. When I submit a date like the following patients.created_at BETWEEN ‘2018-05-22’ AND ‘2018-05-22’ it doesn’t return anything but if I enter BETWEEN ‘2018-05-22’ patients.created_at ‘AND’ 2018-05-23′ it returns a value. I think if I just input two of the same date without entering the time then the time will be 00:00:00 – 00:00:00. How

Advertisement