Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. check date range in between date range

check date range in between date range

Scheduled Pinned Locked Moved Database
databasetutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RA UL PATEL
    wrote on last edited by
    #1

    Hello friends, I need query which will check user supplied date range is in between the existing table startdate and enddate. if any of the date of user supplied date range is in between the tables start date and end date,it should retrun that record from table. for example user supply date range is from 1 may 2012 to 5 may 2012. then query must check that 1 may 2005 2 may 2005 3 may 2005 4 may 2005 5 may 2005 (all dates) is in between startdate and enddate of existing table. please reply...Thanx in advance...

    B V V 3 Replies Last reply
    0
    • R RA UL PATEL

      Hello friends, I need query which will check user supplied date range is in between the existing table startdate and enddate. if any of the date of user supplied date range is in between the tables start date and end date,it should retrun that record from table. for example user supply date range is from 1 may 2012 to 5 may 2012. then query must check that 1 may 2005 2 may 2005 3 may 2005 4 may 2005 5 may 2005 (all dates) is in between startdate and enddate of existing table. please reply...Thanx in advance...

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      select * from tablename where startdate>=@startDate and enddate<=@endDate

      Initialize parameters

      @startDate

      and

      @endDate

      with values


      I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post.

      J 1 Reply Last reply
      0
      • B Blue_Boy

        select * from tablename where startdate>=@startDate and enddate<=@endDate

        Initialize parameters

        @startDate

        and

        @endDate

        with values


        I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Blue_Boy wrote:

        where startdate>=@startDate and enddate<=@endDate

        Probably not a good idea. One end should be inclusive and the other exclusive, for example. where startdate>=@startDate and enddate<@endDate The reason for this is that for a range check you do not want the same value to show up twice in two 'different' ranges.

        1 Reply Last reply
        0
        • R RA UL PATEL

          Hello friends, I need query which will check user supplied date range is in between the existing table startdate and enddate. if any of the date of user supplied date range is in between the tables start date and end date,it should retrun that record from table. for example user supply date range is from 1 may 2012 to 5 may 2012. then query must check that 1 may 2005 2 may 2005 3 may 2005 4 may 2005 5 may 2005 (all dates) is in between startdate and enddate of existing table. please reply...Thanx in advance...

          V Offline
          V Offline
          Vishal D Kolekar
          wrote on last edited by
          #4

          SELECT * FROM tablename where insertdate BETWEEN @startDate and @endDate this is simple but it won't contain @endDate in result set. For that you need to use DATEADD(datepart, number, date) fuction Since your query will be SELECT * FROM tablename WHERE insertdate BETWEEN @startDate and DATEADD(d,1,@endDate) Thanks, Vishal K

          1 Reply Last reply
          0
          • R RA UL PATEL

            Hello friends, I need query which will check user supplied date range is in between the existing table startdate and enddate. if any of the date of user supplied date range is in between the tables start date and end date,it should retrun that record from table. for example user supply date range is from 1 may 2012 to 5 may 2012. then query must check that 1 may 2005 2 may 2005 3 may 2005 4 may 2005 5 may 2005 (all dates) is in between startdate and enddate of existing table. please reply...Thanx in advance...

            V Offline
            V Offline
            vvashishta
            wrote on last edited by
            #5

            Instead of usign Between Operator, you should use FromDate >= @FromDate AND EndDate < DateAdd(D, 1, @EndDate ) (It always perform the accurate process, specially in case when Date Column accepts dates also) Remember EndDate must work with LessThan and FromDate performs on GreaterThanEqualTo

            - Happy Coding - Vishal Vashishta

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups