Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select date

Author  Topic 

Wouter Benoit
Starting Member

23 Posts

Posted - 2008-01-16 : 04:10:13
Hello,

I'm trying to get all the records in my table that have a specific date. But I get no results.

The date column has the data type datetime and is stored like, for example, 11/01/2008 14:45:17 (dd/mm/yyyy)

So if I want to see al the records with date 11 januari 2008 I tried to do

SELECT *
FROM MyTable
WHERE date = '11/01/2008'

I also tried this

SELECT *
FROM MyTable
WHERE date LIKE '11/01/2008%'

But I get no results or no error message.

I checked the forum for an answer and found this solution

Select
*
from
NyTable
Where
MyDateColumn >= '20060114' and
MyDateColumn < '20060115'


but that doesn't work either.

Can someone please tell me what I'm doing wrong.

Thanks in advance
Wouter

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-16 : 04:18:57
Try:-
SELECT *
FROM MyTable
WHERE date >'11 Jan 2008'
AND date <'12 Jan 2008'
Go to Top of Page

Wouter Benoit
Starting Member

23 Posts

Posted - 2008-01-16 : 04:23:28
Thats it

Thanks a lot
Go to Top of Page

Wouter Benoit
Starting Member

23 Posts

Posted - 2008-01-16 : 04:28:24
Thats it

Thanks a lot
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 05:40:44
quote:
Originally posted by visakh16

Try:-
SELECT *
FROM MyTable
WHERE date >'11 Jan 2008'
AND date <'12 Jan 2008'


This wont work if language of the server is not ENGLISH
The correct method is

SELECT *
FROM MyTable
WHERE date >='20080111'
AND date <'20080112'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -