Add a Time Zone Offset to a datetime2 Value in SQL Server (T-SQL)

In SQL Server, the TODATETIMEOFFSET() function was specifically designed to return a datetimeoffset value from a datetime2 value.

Given the fact that the datetime2 data type doesn’t actually support time zone offsets, and datetimeoffset must contain the offset, the TODATETIMEOFFSET() function allows you to specify a time zone offset to use.

This article provides some examples to demonstrate.

Continue reading

About the DATE_BUCKET() Function in Azure SQL Edge

T-SQL includes a DATE_BUCKET() function that allows you to arrange data into groups that represent fixed intervals of time. It returns the datetime value that corresponds to the start of each datetime bucket, as defined by the arguments passed to the function.

As far as I’m aware, the DATE_BUCKET() function is only available in Azure SQL Edge at the time of this writing.

Update: DATE_BUCKET() was introduced in SQL Server 2022.

Continue reading

Difference Between SYSDATE() and NOW() in MariaDB

In MariaDB, the SYSDATE() and NOW() functions are similar in that they return the current date and time.

However, there is an important difference: SYSDATE() returns the time that it executes, whereas NOW() returns the time that the statement started executing.

And when run within a stored procedure or trigger, SYSDATE() will return the time that it executes, whereas NOW() will return the time that the stored procedure or trigger started executing.

Continue reading