Find rows by date from a datetime field in SQL Server

There are many ways to do it. Here mentioned only two of them-

WHERE (dbo.TableName.DateTimeColumnName BETWEEN ‘yyyy-mm-dd 00:00:01’ AND ‘yyyy-mm-dd 23:59:59’)
Or,
WHERE (CONVERT(varchar, dbo.TableName.DateTimeColumnName, 105) BETWEEN ‘dd-mm-yyyy’ AND ‘dd-mm-yyyy’)

Example:
AND (dbo.Retailer.DsrActivityDateTime BETWEEN ‘2014-08-05 00:00:01’ AND ‘2014-08-05 23:59:59’)
AND (CONVERT(varchar, dbo.Retailer.DsrActivityDateTime, 105) BETWEEN ’05-08-2014′ AND ’05-08-2014′)
Advertisements

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