user3107343
user3107343

Reputation: 2299

SQL Query Where Between two date

I tried get all records between after 00:00 and now time

E.g Between 21.02.2014 00:01 and 21.02.2014 10:41(now time)

 Select * from TableName Where Time >=???     and Time < Getdate()

Upvotes: 0

Views: 89

Answers (4)

msi77
msi77

Reputation: 1632

Select * from TableName Where Time between cast(GETDATE() as DATE) and Getdate()

Upvotes: 0

Ben Thul
Ben Thul

Reputation: 32697

If you're on SQL 2008 or later, you can do something like the ff:

select * 
from tablename 
where cast([Time] as date) = getdate() 
    and cast([Time] as time) >= '10:41'

This isn't going to be super performant as the cast makes the predicate non-SARGable. If this is something that you envision doing frequently, you can add persisted computed columns to your table that do the casts for you.

Upvotes: 0

user3107343
user3107343

Reputation: 2299

    Select * from TableName Where DateDiff(day,TimeColumn,getdate()) 

    between 0 and 0

Upvotes: 0

NiiL
NiiL

Reputation: 2827

Select * from TableName Where Time between ??? and Getdate()

Upvotes: 1

Related Questions