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)
 dates and SQL

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-09 : 22:43:54
andy writes "i have a column that is populated with sysdate. i need to retreive information based on date AND time. i need to break down the number of occurences that happen between a given start date and end date, but ALSO that occur in specific time frames. for instance, if i want to retrieve all instances that occur between 2/5/2001 and 2/9/2001 but only for the time frame of 8:00 a.m. to 9:00 a.m. for each of those days (2/5, 2/6, 2/7, 2/8, 2/9).

EXAMPLE: table is called "my_table", and i have a column called "check_in_datetime" and i am trying this code:
select count(*)
from my_table_name
where check_in_datetime >= to_date('05/02/2001','dd/mm/yyyy')
and check_in_datetime <= to_date('09/02/2001','dd/mm/yyyy')
and check_in_datetime >= to_date('8:00:00','hh24:mi:ss')
and check_in_datetime < to_date('9:00:00','hh24:mi:ss');

but i keep getting a count of 0. however, i know there 22 instances because if i query day by day with the appropriate time, the results add up to 22."
   

- Advertisement -