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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:32:58+00:00 2026-06-08T22:32:58+00:00

I want to check the current date if its equal to last three days

  • 0

I want to check the current date if its equal to last three days of month excluding saturdays and sundays…

I can get the last day of month

SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))

I am not sure how to check the getdate() with last three days of month excluding saturdays and sundays..

Will be of great help..
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-08T22:33:00+00:00Added an answer on June 8, 2026 at 10:33 pm
    -- make sure Sunday is the first day of the week:
    SET DATEFIRST 7;
    
    DECLARE 
      @today SMALLDATETIME,
      @nextmonth SMALLDATETIME;
    
    -- today at midnight is the number of days since 1900-01-01
    -- the first day of nextmonth is one month after the first 
    -- day of the current month 
    SELECT 
      @today = DATEDIFF(DAY, '19000101', CURRENT_TIMESTAMP),
      @nextmonth = DATEADD(MONTH, 1, @today-DAY(@today)+1);
    
    -- so if today is greater than 3 days prior to the first of next month
    -- and today is not a Saturday or a Sunday:
    IF @today >= DATEADD(DAY, -3, @nextmonth) 
      AND DATEPART(WEEKDAY, @today) NOT IN (1,7)
    BEGIN
      PRINT 'Bazinga!';
    END
    

    If what you really meant is that you want the last three non-weekend days in the month, then:

    SET DATEFIRST 7;
    
    DECLARE 
      @today SMALLDATETIME,
      @nextmonth SMALLDATETIME;
    
    SELECT 
      @today = DATEDIFF(DAY, 0, GETDATE()),
      @nextmonth = DATEADD(MONTH, 1, @today-DAY(@today)+1);
    
    ;WITH x AS
    (
      -- get the 5 days prior to the first day of next month:
      SELECT TOP (5) d = DATEADD(DAY, -ROW_NUMBER() OVER 
       (ORDER BY [object_id]), @nextmonth) FROM sys.all_objects
    ), 
    y AS
    (
      -- get the last three days that aren't on Sat/Sun:
      SELECT TOP (3) d FROM x 
      WHERE DATEPART(WEEKDAY, d) NOT IN (1,7)
      ORDER BY d DESC
    )
    -- now find out if today is in those three days:
    -- (by definition, today can't be Sat/Sun)
    SELECT 'Bazinga!' FROM y WHERE d = @today;
    

    This will yield no results if today is not in those three days.

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

Sidebar

Related Questions

How may I get the current running application? I want to check if the
I have a column that stores the last modified date. I want to check
Is there any script to check the current date in PHP? I want to
i want to get a list of years and month between two given date
I want to check a Column value when update.If its match insert into another
Okay I have the following problem. I want to get the current dateTime and
I am using PHP's Date functions in my project and want to check weather
I want to perform this date check: The date entered by the user should
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly

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.