Convert UTC to Local Time in SQL Server

When dealing with applications that span multiple time zones, you’ll often want to store timestamps in UTC. That’s usually the best practice – it avoids confusion and ensures consistency. But sooner or later you’ll need to show users dates and times in their own local time zones. There are a few ways to handle this in SQL Server.

Read more

How to Handle Server vs Session Time Zone Settings in SQL Server

Working with dates and times in SQL Server can get tricky, especially once you add time zones into the mix. One common point of confusion is the difference between the server’s time zone and the session’s time zone. If you’re not careful, you can end up with inconsistent data or timestamps that don’t line up with what your users expect.

Let’s look at how SQL Server treats time zones and how you can handle server versus session time zone differences cleanly.

Read more

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.

Read more

MariaDB Composite Date & Time Units Explained

MariaDB includes a bunch of date and time units that you can use when working with date and time values. For example, MONTH is a unit, and HOUR is another unit.

Some units are composite units. Composite units are when two units get combined into one. The naming convention is that each unit name is separated by an underscore. For example, MINUTE_SECOND is for minutes and seconds.

Below are some examples that demonstrate how composite units work in MariaDB.

Read more

How to Add AM/PM to a Time or Datetime Value in MariaDB

MariaDB includes many functions that allow you to return time and datetime values in a variety of formats.

Two functions allow you to format the time portion using a 12 hour clock, with the AM/PM designator are DATE_FORMAT() and TIME_FORMAT().

There are many format specifiers that can be used with these functions, but only a couple that return the AM/PM designator.

Read more