• How can I query a range for the EndTime?

    Adan Member
    SELECT  *
    FROM    Table
    WHERE   CONVERT(datetime, REPLACE(STUFF(StartTime, 11, 1, ' '), '.', ':')) >= :param1
    AND     CONVERT(datetime, REPLACE(STUFF(EndTime, 11, 1, ' '), '.', ':')) < :param2
    

    Explanation: SQL likes a datetime format of yyyy-mm-dd hh:mm:ss.

    The STUFF command "stuffs" a space in position 11 where the hypen (-) is.

    The REPLACE command "replaces" those periods with colons.

    At that point the fields can be CONVERTed to datetime types.

Viewing 0 reply threads
  • You must be logged in to reply to this topic.