Using "between" with datetime fields

  • If StartDateTime is a datetime field, are these where clauses equal.......

    where StartDateTime>='2013-10-01' and StartDateTime<'2013-10-31'

    where StartDateTime>='2013-10-01' and StartDateTime<dateadd(d, 1, '2013-10-31')

    where StartDateTime between '2013-10-01' and '2013-10-31'

    What is the correct way to handle this?

  • They're not equal if StartDateTime is datetime. The correct way to go is up to you to decide.

    where StartDateTime>='2013-10-01' and StartDateTime<'2013-10-31'

    will go from '2013-10-01 00:00:00.000' to '2013-10-30 23:59:59.997'

    where StartDateTime>='2013-10-01' and StartDateTime<dateadd(d, 1, '2013-10-31')

    will go from '2013-10-01 00:00:00.000' to '2013-10-31 23:59:59.997'

    where StartDateTime between '2013-10-01' and '2013-10-31'

    will go from '2013-10-01 00:00:00.000' to '2013-10-31 00:00:00.000'

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanx.

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

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