0

i'm trying to do this line of sql script

select * 
from content 
where first_broadcast_date <= CONVERT(datetime, '26-11-2014', 105) 

the result show me the content which have the value of 'first_broadcast_date' less than '26-11-2014' but not the content which have 'first_broadcast_date = 26-11-2014'

the type of 'first_broadcast_date' field is datetime2(7)

  • 2
    What are the values of `first_broadcast_date`? I would guess there's a time component which occurs after midnight. You would need to use `DATE(first_broadcast_date)` to truncate it to the date part only. – Michael Berkowski Feb 12 '15 at 15:11
  • ^^ Sorry, SQL Server doesn't support `DATE()`. Rather [cast it as a date](http://stackoverflow.com/questions/923295/how-can-i-truncate-a-datetime-in-sql-server) – Michael Berkowski Feb 12 '15 at 15:16
  • 3
    To emphasize M Berkowski . I would use only less than the next day instead of <= So where first_broadcast_date < DATEADD(d, 1 , CONVERT(datetime, '26-11-2014', 105) ) – Sql Surfer Feb 12 '15 at 15:19

1 Answers1

0

because its a date time field you either have a choice to convert to date might give you a bad performance or you can pass date by concatenating 23:59:59 so that you can filter any row in that day

  CREATE TABLE #t (id  INT IDENTITY(1,1), d DATETIME2(7))
     INSERT INTO #t (d)
     VALUES(GETDATE())

 SELECT * FROM #t  WHERE d <= '02/12/2015 23:59:59'
akhil vangala
  • 1,043
  • 1
  • 10
  • 11