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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:09:23+00:00 2026-05-31T10:09:23+00:00

I would like to run weekly reports (from Monday to Sunday) based on a

  • 0

I would like to run weekly reports (from Monday to Sunday) based on a timesheets table, so that I can see what type of jobs are being requested and booked.

In the timesheets table there is a start_dtm and end_dtm

How would I run a query to check for Start and End of the week?

edit: I have the following code which grabs the start and end date:

---------------------------------
--Please set your appropriate values for @REPORT_DATE and @WEEK_BEGINING
DECLARE @REPORT_DATE DATETIME, @WEEK_BEGINING VARCHAR(10)
SELECT @REPORT_DATE = '2012-03-16T00:00:00'
SELECT @WEEK_BEGINING = 'MONDAY'
IF @WEEK_BEGINING = 'MONDAY'
SET DATEFIRST 1
ELSE IF @WEEK_BEGINING = 'TUESDAY'
SET DATEFIRST 2
ELSE IF @WEEK_BEGINING = 'WEDNESDAY'
SET DATEFIRST 3
ELSE IF @WEEK_BEGINING = 'THURSDAY'
SET DATEFIRST 4
ELSE IF @WEEK_BEGINING = 'FRIDAY'
SET DATEFIRST 5
ELSE IF @WEEK_BEGINING = 'SATURDAY'
SET DATEFIRST 6
ELSE IF @WEEK_BEGINING = 'SUNDAY'
SET DATEFIRST 7
DECLARE @WEEK_START_DATE DATETIME, @WEEK_END_DATE DATETIME
--GET THE WEEK START DATE
SELECT @WEEK_START_DATE = @REPORT_DATE - (DATEPART(DW, @REPORT_DATE) - 1)
--GET THE WEEK END DATE
SELECT @WEEK_END_DATE = @REPORT_DATE + (7 - DATEPART(DW, @REPORT_DATE))
PRINT 'Week Start: ' + CONVERT(VARCHAR, @WEEK_START_DATE)
PRINT 'Week End: ' + CONVERT(VARCHAR, @WEEK_END_DATE)
----------------------------------------------
  • 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-31T10:09:24+00:00Added an answer on May 31, 2026 at 10:09 am

    You can use this SQL to determine Monday and Friday of the week of a given date

    SET DATEFIRST 1
    DECLARE @Date date = GETDATE() --give a date here
    
    SELECT
        @Date [SelectedDate], 
        DATENAME(dw, @Date) [SelectedWD],
        DATEADD(dd, -(DATEPART(dw, @Date)-1), @Date) [WeekStart],
        DATENAME(dw, DATEADD(dd, -(DATEPART(dw, @Date)-1), @Date)) [WeekStartWD],
        DATEADD(dd, 7-(DATEPART(dw, @Date)+2), @Date) [WeekEnd],
        DATENAME(dw, DATEADD(dd, 7-(DATEPART(dw, @Date)+2), @Date)) [WeekEndWD]
    
    **Example output**
    SelectedDate    SelectedWD  WeekStart   WeekStartWD WeekEnd     WeekEndWD
    2012-03-16      Friday      2012-03-12  Monday      2012-03-16  Friday
    

    ——————————————— EDIT ———————————————
    USAGE

    This gives you the results for 1 week (only weekdays)

    SET DATEFIRST 1
    DECLARE @Date date = GETDATE() --give a date here
    DECLARE @WeekStart Date, @WeekEnd Date
    
    select @WeekStart = DATEADD(dd, -(DATEPART(dw, @Date)-1), @Date),
    @WeekEnd = DATEADD(dd, 7-(DATEPART(dw, @Date)+2), @Date)
    
    SELECT * FROM myTable WHERE myDate BETWEEN @WeekStart AND @WeekEnd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run something like: select * from table where field in
I would like to run a (extensive) query that produces one line of XML.
I would like to run a process from Python (2.4/2.5/2.6) using Popen , and
I would like to run a cmd.exe that would evaluate environment variables at call
I would like run a PHP script that runs every second to update a
I would like to run a shell window manager kiosk-style WPF app that is
We would like to run a trigger on one database (A) that calls a
I would like to run a calculation to see if the bottom 20px of
I would like to run a sequence of R scripts from the bash command
I would like to run a job through cron that will be executed every

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.