How to select date based on range period.

  • Hi all,

    How to specify where condition to filter date based on range period: Month1 Year1 thru Month2 Year2?

    For example to select all rows with date range from June 2002 thru June 2003?

    Thanks for any help,

    Danny

  • You could use something like:

    Select aDate from TableA

    Where (Month(aDate) >= 5 And Year(aDate) >= 2002)

    And ((Month(aDate) <= 5 And Year(aDate) <= 2003)

  • Depends on the input format. I prefer to convert input to dates first and then compare. You will have to convert anyway.

    set @from = year1 + '-' + month1 + '-01' 
    
    set @to = DATEADD(m,1,year2 + '-' + month2 + '-01')

    select ...
    where [date] >= @from
    and [date] < @to

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Hi Sismith and David

    Thanks for the help.

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

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