CONVERT function can be used to change the format of DATE to various formats like MM/dd/yyy, dd/MM/yyy, yyy/MM/dd, etc. But have you ever noticed that this will produce resultset with a different order if the alias name is used in ORDER BY Clause? Well, I just learned about the formatted date from my recent consulting engagement Comprehensive Database Performance Health Check.
In my very old post SQL SERVER – Query to Find First and Last Day of Current Month – Date Function, I had explained how to find the first day and last day of the current date.
There are many different datetime related functions such as DAY, MONTH, YEAR, DATEDIFF, etc available in SQL Server. For example, YEAR function can be used to extract year value from a date.
This puzzle, I have discovered accidentally. In one of the recent project, I had to display two dates next to each other. Now, when I was doing this, I accidentally did a mistake while I was typing that out. Indeed, this puzzle about strange results when adding two dates.
Recently I received a simple question about AT TIME ZONE feature. This is the new feature which is introduced in SQL Server 2016 and later version of the SQL Server. As this is a relatively new feature the adoption of this feature is also a bit slow. However, let us understand how this function really works in a few simple words.
A very strange question I received the other day in an email about how to convert decimal to time format string.