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 2008 Forums
 Transact-SQL (2008)
 specific datetime in where clause

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2011-04-01 : 11:05:45
How do I write sql statement to select data of certain date sent (datetime format)

for example: where datesent <='2011-04-01-10.44.47.490000'
but my statement is not working.

thanks,

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-04-01 : 11:09:11
try this:

where datesent <= '2011-04-01 10:44:47.490'


Corey

I Has Returned!!
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-04-01 : 11:11:52
I got error message:
"The conversion of a char data type to a datetime datatype resulted in an out of range datetime value"

The reason I want to select specific time frame since there are two set of data in the same report, run the same date but different time...so I want to select time before 10:44 am to get only data that insert in the table before 10:44 am today.

thanks,

quote:
Originally posted by Seventhnight

try this:

where datesent <= '2011-04-01 10:44:47.490'


Corey

I Has Returned!!

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-01 : 11:19:31
Make sure to use unambigious date format
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

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

ntn104
Posting Yak Master

175 Posts

Posted - 2011-04-01 : 11:29:58
Thank you, It worked with your statement now. I previouly forget to remove "-" between date and time.

quote:
Originally posted by Seventhnight

try this:

where datesent <= '2011-04-01 10:44:47.490'


Corey

I Has Returned!!

Go to Top of Page
   

- Advertisement -