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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Working with DateTime

Author  Topic 

hasanali00
Posting Yak Master

207 Posts

Posted - 2006-02-02 : 07:26:09
I feel dreadful asking this simple question:

I have a column: MyDateTime DateTime (8)

Now I want to retrive data where MyDateTime is greater than 01/02/2006.

SELECT *
FROM MyTable
WHERE (MyDateTime > 01 / 02 / 2006)

However, this statement is not working properly. I get all the rows where MyDateTime is less than 01/02/2006

Can someone help me writing the correct statement
Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-02 : 08:08:13
>> Now I want to retrive data where MyDateTime is greater than 01/02/2006.
01/02/2006 is MM/DD/YYYY or DD/MM/YYYY
Advicable to specify your date in YYYY-MM-DD
SELECT * FROM MyTable WHERE MyDateTime > '2006-01-02'

or
SELECT * FROM MyTable WHERE MyDateTime > '2006-02-01'



----------------------------------
'KH'


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-02 : 08:48:53
Also refer
http://www.sql-server-performance.com/fk_datetime.asp

Madhivanan

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

- Advertisement -