Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2017
    Posts
    2

    Answered: Query to retrieve records for last 5 full year plus current year

    I am using the following query to retrieve last 5 years data

    Date_Field >= Current_Date - 5 years

    But this gives me till last 5 year where the last full year is not covered.

    For eg : It retrieves data from 3/2012 but i need full 2012 year ( including 1st and 2 nd month)

    How to achieve this in query?

    Thanks in advance

  2. Best Answer
    Posted by mark.bb

    "
    Code:
    Date_Field >= current date - (day(current date) - 1) days - (month(current date) - 1) month - 5 years
    "


  3. #2
    Join Date
    Apr 2012
    Posts
    1,143
    Provided Answers: 27
    If the types of your columns are suitable, you can try:

    year(date_field) >= CURRENT YEAR - 5 years

  4. #3
    Join Date
    Jul 2016
    Location
    Moscow
    Posts
    294
    Provided Answers: 45
    Code:
    Date_Field >= current date - (day(current date) - 1) days - (month(current date) - 1) month - 5 years
    Regards,
    Mark.

  5. #4
    Join Date
    Mar 2017
    Posts
    2
    Thanks Mark ..This is exactly what i was looking for

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •