Skip to content
June 5, 2009 / kiranpatils

How to get only DATE portion out of DATETIME column in MSSQL?

Challenge:

One of my colleague was writing a query to get records between start date and enddate.

SELECT EmployeeName From Employees WHERE EmployeeJoiningDate >= @startDate AND EmployeeJoiningDate<=@endDate
&#91;/sourcecode&#93;

it was working fine but some records are not showing up in the list because it was checking time also. Which he don't want to compare..So, how to get just date part and compare it with provided params?
<h4>Solution:</h4>
We found the way for it using


SELECT CONVERT(VARCHAR(10),GETDATE(),101) --101 = mm/dd/yyyy

it made his work simple!!. So, just convert your date and then compare..for brevity i left up to you to write a new sql statement🙂

Here 101 is one of the style to get date. for list of style go to MSDN

Happy Programming!

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

%d bloggers like this: