• drew.allen (6/22/2016)


    You don't need CASE statements.

    select *

    from tickets

    where ticketdate = CAST(DATEADD(HOUR, -6, GETDATE()) AS DATE)

    If you have a range that you are trying to fit into another range of the same size, you can chop up the first range and rearrange the parts so that they fit, or you can adjust the whole range so that they fit. Generally the second approach is simpler, but most people take the first approach, because they assume that they shouldn't move the piece that already overlaps.

    Drew

    Yes, I see your point. That is definitely more elegant.

    I don't know if the OP's Sybase database supports the DATE data type. If it only supports the old DATETIME data type, you'd need to cut off the time part, which you can do with DATEDIFF:

    select *

    from tickets

    where ticketdate = CAST(DATEDIFF(DAY, 0, DATEADD(HOUR, -6, GETDATE())) AS DATETIME)