Use of BETWEEN and DATETIME

  • Scary question, I went with what the answer was but I was ready for a long discussion over a typo.

  • venoym (9/27/2011)


    I thought the question was fine. The trickery would have gotten closer to an 80% failed if the possible answers had included the number 4. That was my first red flag that there was a trick when the "correct" answer was not in the answer list.

    Uh, why do you think that the answer would have been four? It would have been 3 actually.

  • Wonderfull straightforward question. I see no trick in it.

    Considering the amount of times I have seen this behavior of Between cause bug in code I was not suprised at the amount of wrong answers. 😛

    Also not suprised at the amount of dissussion already.

    For a successful technology, reality must take precedence over public relations, for Nature cannot be fooled.

    Richard P. Feynman

    😎

  • Thanks for the question

  • tricky question, went over the head. would be easier if there was < and > dates..

    Didn't knew, between operator works like that too 🙁

    I thought I can enter any dates irrespective of order and it will fetch the results...

    Atleast i know now.

    Regards,

    Sushant

    Regards
    Sushant Kumar
    MCTS,MCP

  • Great question. Just like real life debugging. Read carefully and avoid making incorrect assumptions.

  • Ha, I read the code the way I would have written it Date1 first with the lesser datetime and Date2 second with the greater datetime. My bad. Good question. There should have been a warning: "There are tricks in this code, make sure you have enough caffeine before attempting an answer"

  • Ola L Martins-329921 (9/27/2011)


    Of course, failing the question I will argue that this question should be under the category (yet to be added) READING... 😉

    That may not be a bad idea. Add a category of code review or something like that. Of course, that may invite questions where the answer is more a matter of opinion.

  • I agree - definitely more of a trick question. If you reverse the @DATE1 and @DATE2 in the BETWEEN query it actually makes quite an interesting question - will it return 3 or 5 rows? That's what I was trying to answer. 😀

  • jts_2003 (9/27/2011)


    I agree - definitely more of a trick question. If you reverse the @DATE1 and @DATE2 in the BETWEEN query it actually makes quite an interesting question - will it return 3 or 5 rows? That's what I was trying to answer. 😀

    Same here.

    Between = >/ or </

    or just

    Between = > or <

    Regards,

    Sushant

    Regards
    Sushant Kumar
    MCTS,MCP

  • jts_2003 (9/27/2011)


    I agree - definitely more of a trick question. If you reverse the @DATE1 and @DATE2 in the BETWEEN query it actually makes quite an interesting question - will it return 3 or 5 rows? That's what I was trying to answer. 😀

    3 rows. If you don't add a time, it assumes midnight. So the BETWEEN would be Jan 2 at midnight to Jan 4 at midnight, and only the rows for the 2nd and 3rd will be selected.

  • Good question, further emphasizes that you need to closely evaluate any code you're looking at.

  • Tricky but I got it! I acutally had a similar situation recently where I had flubbed the date parameters so this was still freshly burned into my memory! 😀

  • Devil is in the detail... thanks, nice QoD!

  • Good question - without the reversed order of the variables in the assignment of values, which was clearly designed to put a 'gotcha' into the mix. However, as many have suggested, it's a good lesson in paying attention to the details that appear to be on the periphery of the apparent problem, but which end up being the real cause of the problem.

    So...a humbled thanks!

    Rob Schripsema
    Propack, Inc.

Viewing 15 posts - 31 through 45 (of 66 total)

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