>From the code you posted the date and time are one column, so you cannot
query time without using the date.  More code must write to extract the time
piece of the data.  I have used CONVERT to help isolate the time in the
table's date column.

(But be aware that CONVERT is not an SQL standard, it's an extension of SQL
Server. If you are a SQL Server only environment it's not a problem.)

Here's a link to SQL Server 2005 BOL which explains casting and converting:
 http://msdn.microsoft.com/en-US/library/ms187928(v=SQL.90).aspx.

SQL Sever Central articles are also great tools to further understanding the
inner workings of SQL Server: http://www.sqlservercentral.com


On Fri, Jul 30, 2010 at 9:36 PM, Jeena Ajiesh <[email protected]> wrote:

> *Dear Friends ,*
> *Thanks for the Replies.*
> *The Date format is in MM/DD/YYYY.*
> *The Datetime which im passing is as 9/2/2010 7:30 PM.*
> *In which date checking is working when i gave the query in between.*
> *But Wen i checked the time between from time and totime. it shows
> nothing.*
> *
>
> Query was: Select message from NetMessage where '7:30:00 PM' between
> FromTime and ToTime.
> From time contain 7:00:00 PM and ToTime contain 8:00:00 PM
> I know this is not the correct way to use the value in query
>
> Any Solutions Pls?
>
> *
>
> On Fri, Jul 30, 2010 at 5:32 PM, Jamie Fraser <[email protected]>wrote:
>
>> Use a bit of initiative here; take the SQL below, execute it in
>> Management Studio, if it returns nothing then try alternative date
>> formats. This is an extremely simple problem!
>>
>> On Thu, Jul 29, 2010 at 1:43 PM, Jeena Ajiesh <[email protected]> wrote:
>> > Thanks for the reply.
>> > I tried this option, but still no result.
>> >
>> > On Thu, Jul 29, 2010 at 2:57 PM, Jamie Fraser <[email protected]>
>> > wrote:
>> >>
>> >> DECLARE @TargetDate datetime
>> >> SET @TargetDate = '7/29/2010 9:15:00'
>> >>
>> >> SELECT
>> >>     Message
>> >> FROM
>> >>     MyTable
>> >> WHERE
>> >>     FromDate <= @TargetDate
>> >>     AND
>> >>     ToDate >= @TargetDate
>> >>
>> >> On Wed, Jul 28, 2010 at 9:32 AM, Jeena Ajiesh <[email protected]>
>> wrote:
>> >> > Dear friends,
>> >> >
>> >> > im stucked in a problem.
>> >> > in database im having  fromdate,todate, message and id
>> >> > fromdate & todate contains dates with time.
>> >> >
>> >> > Eg in DB:Fromdate
>> >> >   Todate                             Message   Id
>> >> >                  7/25/2010 10:00:00 AM   8/1/2010 12:00:00 PM
>> >> > Test        abc
>> >> >                  7/25/2010 9:00:00 PM      8/1/2010 10:00:00 PM
>> >> > Hello     abc
>> >> >
>> >> > Im passing a date 7/29/2010 9:15:00 PM.So i need to get the message
>> from
>> >> > table as 'Hello'
>> >> >
>> >> > i tried a query SELECT MESSAGE FROM TABLENAME WHERE '7/29/2010
>> 9:15:00
>> >> > PM
>> >> > BETWEEN FROMDATE AND TODATE
>> >> > Can u please help in giving a correct query to retrieve the correct
>> >> > message
>> >> > in DB based on the datetime passing.
>> >> >
>> >> >
>> >> > ***************
>> >> > Thanks & Regards,
>> >> > Jeena Ajiesh
>> >> >
>> >> >
>> >
>> >
>> >
>> > --
>> > ***************
>> > Thanks & Regards,
>> > Jeena Ajiesh
>> > Email: [email protected]
>> >            [email protected]
>> >
>> >
>>
>
>
>
> --
>  ****************
> **Thanks & Regards,
> Jeena Ajiesh
> Email: [email protected]
>            [email protected]*
>
>

Reply via email to