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 4617978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:12:04+00:00 2026-05-22T02:12:04+00:00

I am writing a statement to pull accounts that are due the soonest. My

  • 0

I am writing a statement to pull accounts that are due the soonest. My query currently sorts on month and day as year is irrelevant. Is there anyway to set the current month and day as the top most values? rather than jan 01?

SELECT *
FROM clients
WHERE LiveDate IS NOT NULL
Order by DATEPART(month, LiveDate), DATEPART(day, LiveDate)

Would I just need to split it into two queries one looking for after the current month day, one looking for before, and join them so that they are in the right order

EXAMPLE:

date founded || Annual function
01/01/2011   || beach outing
11/03/2010   || family day
23/03/2009   || Movies
05/04/2000   || Girls night out
10/05/2005   || Cricket function
29/07/2011   || candle lit formal dining
30/07/2008   || childrens day
04/08/2005   || board games day
03/012/2006  || pizza night
20/012/2001  || camping trip

As this is an annual outing the year does not matter. I want to pull them in order of the event closest to now through to the end of the year, then from the start of the year through to today.

so the results would be in this order based on a current day of: 23/06/2011

date founded || Annual function 
29/07/2011   || candle lit formal dining 
30/07/2008   || childrens day 
04/08/2005   || board games day 
03/012/2006  || pizza night 
20/012/2001  || camping trip              _ _ _ _ _ _ _ New year _ _ _ _ _  
01/01/2011   || beach outing 
11/03/2010   || family day 
23/03/2009   || Movies 
05/04/2000   || Girls night out 
10/05/2005   || Cricket function
  • 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-05-22T02:12:04+00:00Added an answer on May 22, 2026 at 2:12 am
    SELECT *
    FROM clients
    WHERE LiveDate IS NOT NULL
    ORDER BY ABS(DATEDIFF(day, LiveDate, GETDATE())
    

    UPDATE

    Sorry, didn’t get it at first that only the proximity to the current day and month, but not year, should be taken into account when sorting.

    So maybe like this:

    SELECT *
    FROM clients
    WHERE LiveDate IS NOT NULL
    ORDER BY
      ABS(
        DATEDIFF(
          day,
          DATEADD(year, DATEDIFF(year, LiveDate, GETDATE()), LiveDate),
          GETDATE()
        )
      )
    

    ?


    UPDATE 2

    Based on the examples provided, this should do the job:

    …
    ORDER BY
      (MONTH(LiveDate) - MONTH(GETDATE()) + 12) % 12,
      DATEADD(year, YEAR(GETDATE()) - YEAR(LiveDate), LiveDate),
      YEAR(LiveDate)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading about Delphi's Exit statement (see here for instance), I cannot ignore that writing
I'm writing a SQL statement to select a user on a table if that
I'm writing the following statement to select names that starts with a range of
When writing a switch statement, there appears to be two limitations on what you
I'm currently writing an application that's meant to scale with data brought in from
I am writing a SQL query that I would like to add a column
I need help writing select statement that will do an average of the most
Beginner's question here: If I'm writing an If statement that I want to pertain
I'm writing an sql statement (see below) which compares 2 serial numbers on 2
As far as I know when writing a conditional statement in C such as

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.