Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:43:40+00:00 2026-06-05T04:43:40+00:00

How do I go back to last April 4th (from today), minus 4 years,

  • 0

How do I go back to last April 4th (from today), minus 4 years, and return that date?

I could start by checking if today’s date is before or after April 4 this year and go from there, but I would be interested to see different approaches to this issue.

This will be part of a larger select statement, so a self-contained SELECT or a function would be the best solution.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:43:42+00:00Added an answer on June 5, 2026 at 4:43 am

    I can’t find any neater way of doing this – I normally fall back on my tried and true DATEADD/DATEDIFF pair to do date calculations, but I can’t think of a way to take account of how far through the year we are neatly – so we get a CASE expression as well:

    select DATEADD(year,
    DATEDIFF(year,'20010101',CURRENT_TIMESTAMP)
    - CASE WHEN DATEPART(month,CURRENT_TIMESTAMP) IN (1,2,3) THEN 1
        WHEN DATEPART(month,CURRENT_TIMESTAMP) = 4 AND
            DATEPART(day,CURRENT_TIMESTAMP) < 4 THEN 1
        ELSE 0 END
    ,'19970404')
    

    For testing particular dates to check edges conditions:

    declare @dt datetime
    set @dt = '20120403'
    select DATEADD(year,
    DATEDIFF(year,'20010101',@dt)
    - CASE WHEN DATEPART(month,@dt) IN (1,2,3) THEN 1
        WHEN DATEPART(month,@dt) = 4 AND
            DATEPART(day,@dt) < 4 THEN 1
        ELSE 0 END
    ,'19970404')
    

    If you just need 4th April of the year four years before the current year, then

    DATEADD(year, DATEDIFF(year, '20010101', @dt), '19970404') 
    

    will suffice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to return back to last activity if user click in notification.
this post is off the back of my last question (thought i'd start a
The last time I did any serious Java coding was back around the turn
Back in the days before Visual Studio Web Server we would host our local
Back in the past, i found a third party webpage that was able to
When looking back at last weeks work (identical to many others), I've found myself
when tapping just on the Back button it last 1-1.5secs (iOS 4-5 iPhones) seconds
Backspace is the browser hotkey for Navigate Back To The Last Page. I know
Any one know how to go back to the last page after a user
I am trying to redirect users to the last page they logged in from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.