Search results
select min(period) as period, MIN(date), MAX(date) from (select t.*, (select min(date) from t t2 where t2.period <> t.period and t2.date > t.date) as nextp from t ) t group by nextp The inner subquery gets the date of the next period.
27 cze 2019 · Learn SQL Server date functions to get beginning and ending periods such as first day of the week, month, quarter, year, and dynamic end dates.
20 kwi 2017 · SELECT p_begin.ProcessOrder, p_begin.ProcessDate as ProcessBegin, DateAdd(day, -1, p_end.ProcessDate) as ProcessEnd FROM Process p_begin LEFT OUTER JOIN Process p_end ON p_end.ProcessOrder = p_begin.ProcessOrder + 1
4 kwi 2012 · SET DATEFIRST 1 will make the first day of the week monday. SELECT DATEADD(DAY, 1 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE)) [WeekStart], DATEADD(DAY, 7 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE)) [WeekEnd] EDIT.
20 lip 2013 · We can use a query like below to get Quarter’s Start and End Date for a given date. DECLARE @AnyDate DATETIME SET @AnyDate = GETDATE() SELECT @AnyDate AS 'Input Date', DATEADD(q, DATEDIFF(q, 0, @AnyDate), 0) AS 'Quarter Start Date', DATEADD(d, -1, DATEADD(q, DATEDIFF(q, 0, @AnyDate) + 1, 0)) AS 'Quarter End Date'
18 lip 2019 · Learn to calculate Start / First of Week, End of Week, Start of Next Week, Year, Quarter, and Month of the week, Week Numbers and more in T-SQL (Jeff Moden)
SELECT task_id, start_date, end_date FROM tasks WHERE (end_date -start_date) > INTERVAL 5 DAY; In the above query, we subtract the "start_date" from the "end_date" to calculate the duration of each task and then use the INTERVAL function to specify a duration of 5 days for comparison.