SQL CONVERT function and SQL dates

I recently had a colleague stop by asking how he could eliminate the time portion of a date when he extracted the data from a SQL table to MS-Excel. He was having trouble grouping dates in Excel because the data contained the time part as well. My first thought was using DATEPART but my wonderful DBA team member Mary T. suggested using the CONVERT function with the style 101. Worked out perfectly. Here is a sample code displaying the results. There are other styles as well with the CONVERT function.

SELECT 
	[OrderDate], 
	CONVERT(varchar(10), [OrderDate], 101) AS JustOrderDate 
FROM [Northwind].[dbo].[Orders]

Results:

OrderDate                                  JustOrderDate
1996-07-04 00:00:00.000        07/04/1996
1996-07-05 00:00:00.000        07/05/1996

Advertisements

2 thoughts on “SQL CONVERT function and SQL dates

  1. Neat blog! Is your theme custom made or did you download it from somewhere?

    A theme like yours with a few simple adjustements would really make my blog jump out.
    Please let me know where you got your design. Appreciate it

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s