Need to run query with timestamp criteria

  • Hello,

    I am trying to run a query with the following table , the column acc_time is datetime data type

    acc_time

    2011-12-11 10:46:00.000

    2011-12-11 10:46:00.000

    2011-12-11 04:16:00.000

    2011-12-11 10:46:00.000

    2011-12-11 10:46:00.000

    2011-12-11 10:46:00.000

    2011-12-11 12:24:00.000

    2011-12-11 12:24:00.000

    2011-12-11 13:19:00.000

    2011-12-11 13:30:00.000

    2011-12-11 16:06:00.000

    2011-12-11 18:25:00.000

    2011-12-11 18:25:00.000

    2011-12-11 18:25:00.000

    Basically, I need to have the query with following in the where clause; the main difficulty I am having with the time (1st condition)

    1. During the hours of 6-10 am and 3-7 pm

    2. Separately for these three periods: Jan 1- Mar 31, 2012; Apr 1 – June 30, 2012 and July 1 – Sept 30, 2012

    Any suggestions would be appreciated.

    Aj

  • Cast the DateTime column to Time datatype, and then use that in your Where clause. Should work for what you need.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply