How to trim TIME part in DATETIME values? A reader wanted to keep only the date and the hour, so here are ways to cut off the minutes and seconds.
Puzzle – Datatime to DateTime2 Conversation in SQL Server 2017
At PASS, SQL Server expert Christopher Savage showed me a puzzle on DateTime to DateTime2 conversion in SQL Server 2017. I still have no answer, so can you solve it?
Formatted Date Alias in ORDER BY: Sort by the Real Date in SQL Server
A formatted date alias can change ORDER BY from a date sort into a text sort. The tests here reproduce the wrong order, show three ways to sort by the real date, and explain the two errors you hit when you try to be clever with the alias.
SQL SERVER – Simple Method to Find FIRST and LAST Day of Current Date
I calculate the FIRST and LAST Day of Current Date using explicit date boundaries. The historical sample starts on October 28, 2017.
SQL SERVER – Puzzle – How Does YEAR Function Work?
SELECT YEAR(35000/20) returns 1904, which looks strange. This puzzle shows how the YEAR function treats a plain integer. Can you explain the result?
Longest Streak of Consecutive Days in T-SQL: Gaps and Islands
Find the longest streak of consecutive days in T-SQL with gaps and islands: group dates with ROW_NUMBER, handle duplicates, and list gaps.






