0

I use SQL Server. I have a column of type datetime in the following format:

2014-07-14 09:18:13.000

How can I write a select statement so that it only selects the dates that are newer than a specific date and specific date + time?

EDIT SELECT * FROM mytable WHERE mydatefield > '2014-07-22'

the datetime column: 2014-07-22 11:44:08.000

I get the data. I should not get the data because it says bigger than.

Stefan Frederiksen
  • 135
  • 2
  • 3
  • 15

2 Answers2

1

For specific dates:

SELECT * FROM mytable WHERE mydatefield > '2014-07-14'

For specific dates and times:

SELECT * FROM mytable WHERE mydatefield > '2014-07-14 09:18'

Put the dates/times you want in the query.

danmullen
  • 2,556
  • 3
  • 20
  • 28
  • Is not working. The data in the field says: 2014-07-22 and I write the same date in the query and stil get the data. – Stefan Frederiksen Oct 09 '14 at 08:47
  • Not sure what the problem is - post your full query please along with what you want/expect to be returned. – danmullen Oct 09 '14 at 08:48
  • 2
    You will get the data because without a time, it will default to '00:00:00.000'. Change the WHERE clause to use the following day or add the time '23:59:59.999' to the date. – danmullen Oct 09 '14 at 08:53
0

try this

select * from table where datetimecolumn >(select 'speicifdate' from othertable)
Recursive
  • 954
  • 7
  • 12