Thursday, March 29, 2012

failed to search using d.DateCreated >='05/07/2007' AND d.DateCreated<= '05/07/2007'

hi all programmers.
i want to find the record that created on only 05/07/2007
the datetime in my database is 5/7/2007 4:09:00 PM
i used this (d.DateCreated >='05/07/2007' AND d.DateCreated<= '05/07/2007' ) inside the where clause.
but it returns no result.
please help me on this issue. thanks for all helps.

Try this


d.DateCreated >='05/07/2007' AND d.DateCreated< '06/07/2007'

|||

Or, to avoid ambiguity caused by your connection's language settings, you might want to use the following date format:

yyyy-mm-dd hh:mi: ss.mmm

<ignore the space after mi: - excluding it from forum posts results in this: miTongue Tied >

e.g.

d.DateCreated >= '2007-07-05 00:00:00.000' AND d.DateCreated < '2007-07-06 00:00:00.000'

or

d.DateCreated >= '2007-05-07 00:00:00.000' AND d.DateCreated < '2007-05-08 00:00:00.000'

(depending on the format of the date that you oiginally provided)

Chris

|||try this one

CONVERT(smalldatetime,CONVERT(varchar(10),d.DateCreated,101)) >=CONVERT(smalldatetime,'05/07/2007') AND
CONVERT(smalldatetime,CONVERT(varchar(10), d.DateCreated,101))<= CONVERT(smalldatetime,'05/07/2007')|||The where clause you specified is only looking for EXACTLY midnight, 5/07/2007 12:00am. If you want to search for anything on 5/7 use:

DateCreated >='5/7/2007' AND DateCreated < '5/8/2007'

No comments:

Post a Comment