Dates and Times in SQL Server: more functions you should never use

Previously we looked at four built-in functions to get the current date and time in SQL Server and Azure SQL Database using Transact-SQL (T-SQL). We identified that out of the options provided, SYSUTCDATETIME() is the recommended method because it relies on Coordinated Universal Time (UTC), and uses the DATETIME2 data type which has a much higher[…]

watch

Dates and Times in SQL Server: T-SQL functions to get the current date and time

We have come on quite a journey so far. SQL Server and Azure SQL Database provide date and time data types to help you design the best possible database. You can read more about that here: Dates and Times in SQL Server: DATETIME Dates and Times in SQL Server: SMALLDATETIME Dates and Times in SQL[…]

Dates and Times in SQL Server: the science of time redux

Last time, we began an in-depth look at how time is measured. This post continues our journey. If any of you are students of Albert Einstein and his theory of relativity, this might seem familiar. How does a computer know what time it is? Inside the guts of every computer is a clock (called a[…]

Dates and Times in SQL Server: the science of time

Now that we have covered the various date and time data types (see the post from last time) in SQL Server and Azure SQL Database, it’s time to review what we know about time itself and how it is measured, so that we have a basic understanding of how and when to use these data[…]

Why is a value in DATETIME2 8 bytes, but in BINARY it is 9 bytes?

In the #sqlhelp Slack channel on the SQL Server Community Slack workspace last month, Jemma Hooper asked: When trying to CAST or CONVERT a datetime2 value to binary(8), I’m getting a “binary or text data would be truncated” error. This seems really weird in context with the fact that SELECT DATALENGTH() on a DATETIME2 value[…]