datetime stamp question

  • Hey,

     

    I have a datetime stamp that returns values in this format: 2005-03-08 13:15:44.880

    What I want to do is do a range filter on this column where it is within 1 minute of the value in that field currently.

     

    For example, for this value, I want to do a range from 2005-03-08 13:14:44.880 to 2005-03-08 13:16:44.880

     

    Any ideas?

    Thanks,

    Michael

     

     

  • Here's a straight forward way that probably won't use available indexes...

    SELECT yada-yada

      FROM yourtable

     WHERE datediff(mi,0,datecolumn)= datediff(mi,0,datetimelookingfor)

    Here's a less straight forward way that will use available indexes...

    SELECT yada-yada

      FROM yourtable

     WHERE datecolunmn >= dateadd(mi,datediff(mi,0,datetimelookingfor),0)

       AND datecolunmn <  dateadd(mi,datediff(mi,0,datetimelookingfor)+1,0)

    Sorry, forgot to add the "dateadd".  Had to update this post.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Would this help?

    select  *

    from  myTable

    where dateColumn >= dateadd(mi, -1, '2005-03-08 13:15:44.880')

    and dateColumn <= dateadd(mi, 1, '2005-03-08 13:15:44.880')

    /Kenneth

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

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