0

This is the function I was using to group by 30 mins of intervals in SQL:

convert(time(0),dateadd(minute,(datediff(minute,0,a.Datetime)/30)*30,0))

where for example Datetime is 2023-03-09 00:26:01.6830000 grouped as 00:00:00.

First column values are the Datetime and second is after grouping it to 30 mins intervals

I need equivalent function in Databricks SQL.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Can you show readers what you have tried so far, or where in the documentation you are looking? – halfer May 27 '23 at 15:09

1 Answers1

0

The following query works for the data in sql server:

select  *,convert(time(0),dateadd(minute,(datediff(minute,0,t1.dt)/30)*30,0)) from t1;

enter image description here

  • Its equivalent in databricks sql is as shown in the below query:
select  *,date_format(dateadd(minute,floor(datediff(minute,'1900-01-01',t1.dt)/30)*30,'1900-01-01'),'HH:mm:ss') from t1;

enter image description here

Saideep Arikontham
  • 5,558
  • 2
  • 3
  • 11