Convert DateTime Column To Date In SQL Server

Welcome to Excel Jet Consult blog post. In this tutorial, we will learn how to convert DateTime to Date in SQL Server. Let’s get started

Often time, when we import data from Excel to SQL Server that has Date, the Date Excel column will automatically be displayed as DateTime column in SQL. In the first caption below, we discovered that in Excel, our date is displayed using the Short Date format.

However, when we imported the same data to SQL and retrieved the data using query command, we discovered that, not only was the data transposed from dd/mm/yyyy excel format to yyyy-mm-dd sql format, we also discovered that we have 00:00:00:000-time format which we don’t need.

Essentially, what we are going to do is write a query and use the SQL Convert function to display only the Date.

Therefore, in the query window, execute the following query:

select [Order ID], convert(date,[Order Date])as [Order Date], convert(date,[Ship Date]) as [Ship Date], [Ship Mode], [Customer ID] Segment, State, Sales, Quantity Discount, Profit from Orders$

Finally, select the query and click on Execute or press F5 on the Keyboard

From the caption below, we can see that we have proper date format

Posted in Blog.

Leave a Reply

Your email address will not be published. Required fields are marked *