How to Get the Current Date and Time with Time Zone Offset in SQL

To get the current date and time with a time zone offset in SQL, use the CURRENT_TIMESTAMP function. This function takes an optional argument, which is the time zone offset. For example, if you wanted to get the current date and time with a UTC+2 offset, you would use the following query:

SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC+2';

Examples

Let's look at a few examples of how this function can be used. Suppose you want to get the current date and time with a UTC+5 offset. You would use the following query:

SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC+5';

This query would return the result 2020-07-27 11:00:00, which is the current date and time with a UTC+5 offset.

Additional Info

The CURRENT_TIMESTAMP function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database. 🤓

Want to build your own LLM Apps with AirOps👇👇