SQL Query to Convert Date Field to UTC
Last Updated :
25 Oct, 2021
In SQL, dates are complicated for newbies, since while working with the database, the format of the date in the table must be matched with the input date in order to insert. In various scenarios instead of date, DateTime (time is also involved with date) is used. In this article, we will discuss how to convert Date Field to UTC in SQL. For this article, we will be using the Microsoft SQL Server as our database.
Step 1: Create a Database. For this use the below command to create a database named GeeksForGeeks
Query:
CREATE DATABASE GeeksForGeeks
Output:

Step 2: Use the GeeksForGeeks database. For this use the below command
Query:
USE GeeksForGeeks
Output:

Step 3: Create a demo table inside the database GeeksForGeeks
Query:
CREATE TABLE Demofordatetime(
demonumber int);
Output:

Step 4: Write a command to display the current date and time in the default format using the GETDATE() command. We will later convert this to the UTC time i.e. Coordinated Universal Time.
Query:
SELECT GETDATE() AS CurrentTime
CurrentTime is the variable here.
Output:

Step 5: Write a similar command to display the current date and time in the UTC field using the GETUTCDATE() command.
Query:
SELECT GETUTCDATE() AS UTCTime
UTCTime is the variable here.
Output:

Step 6: Now write and run both commands simultaneously to see the value of the current date and time both according to the local time zone as well as according to UTC.
Note - The time difference between IST(Indian Standard Time) and UTC(Coordinated Universal Time) is as follows:
IST - UTC = 5:30 hours i.e. IST is ahead of UTC by 5 hours and 30 minutes.
Query:
SELECT GETDATE() AS CurrentTime
SELECT GETUTCDATE() AS UTCTime
Output:
Similar Reads
SQL Query to Convert Date to Datetime In this article, we will look at how to convert Date to Datetime. We can convert the Date into Datetime in two ways. Using CONVERT() function: Convert means to change the form or value of something. The CONVERT() function in the SQL server is used to convert a value of one type to another type.Conve
1 min read
SQL Query to Convert Datetime to String In order to convert a DateTime to a string, we can use CONVERT() and CAST() function. These functions are used to converts a value(of any datatype) into a specified datatype. CONVERT() Function Syntax: CONVERT(VARCHAR, datetime [,style])VARCHAR - It represent the string type.datetime - It can be the
3 min read
SQL Query to Convert Datetime to Epoch Converting a datetime value to Epoch time is a common operation in SQL, particularly when working with timestamps in various applications. In this article, We will learn a step-by-step process of creating a SQL database, inserting datetime values and converting those values into Epoch time using SQL
3 min read
SQL Query to Convert UTC to Local Time Zone In this article, we will cover how to convert UTC to the local time zone for the different times of UTC in the database. Now, let's execute a query that converts the UTC to local time zone using MSSQL as our database in detail step-by-step. Step 1: Creating a database time_converter by using the fol
2 min read
SQL Query to Convert DateTime to Date in SQL Server In SQL Server, working with DateTime data types can be a bit complex for beginners. This is because DateTime includes both the date and time components, while many scenarios only require the date. Whether you're working with large datasets, performing data analysis, or generating reports where time
5 min read