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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:16:38+00:00 2026-05-31T20:16:38+00:00

I have the following code: DECLARE @testDate date –SET @testDate=dateadd(wk, 5830, 0) SET @testDate=’2011-09-26

  • 0

I have the following code:

DECLARE @testDate date
--SET @testDate=dateadd(wk, 5830, 0)
SET @testDate='2011-09-26 00:00:00.000'

SELECT *
FROM dbo.timesheets
WHERE @testDate BETWEEN convert(datetime, start_dtm, 120) and convert(datetime, end_dtm, 120)

PRINT @testDate

It should convert the value 5830 back to the date format and then check between start_dtm and end_dtm

I have tested this by hard coding the value from the database in the above code and i still dont see any records. The printed @testdate shows up like this: 2011-09-26

I am creating a week_ref which i am passing via querystring. The timesheets report will then convert the week_ref eg, ‘5830’ to the date and check if its between the start_dtm and end_dtm. In theory it should display results as its checking if values are between start and end.

Any ideas? or help on debugging?

EDIT: row in the timesheets table:

Example row from timesheets table

Here is the query i am trying to get working:

DECLARE @week_ref INT
DECLARE @weekDate date

set @weekDate=dateadd(wk,@week_ref,0)



SELECT     ts.staff_member_ref, sm.common_name, sm.department_name, DATENAME(MONTH, ts.start_dtm) + ' ' + DATENAME(YEAR, ts.start_dtm) AS month_name, 
                      ts.timesheet_cat_ref, cat.desc_long AS timesheet_cat_desc, grps.grouping_ref, grps.description AS grouping_desc, ts.task_ref, tsks.task_code, 
                      tsks.description AS task_desc, ts.site_ref, sits.description AS site_desc, ts.site_ref AS Expr1, 
                      CASE WHEN ts .status = 0 THEN 'Pending' WHEN ts .status = 1 THEN 'Booked' WHEN ts .status = 2 THEN 'Approved' ELSE 'Invalid Status' END AS site_status, 
                      ts.booked_time AS booked_time_sum,

start_dtm, CONVERT(varchar(20), start_dtm, 108) + ' ' + CONVERT(varchar(20), start_dtm, 103) AS start_dtm_text, booked_time,
end_dtm, CONVERT(varchar(20), end_dtm, 108) + ' ' + CONVERT(varchar(20), end_dtm, 103) AS end_dtm_text


FROM timesheets AS ts 

INNER JOIN timesheet_categories AS cat ON ts.timesheet_cat_ref = cat.timesheet_cat_ref 
INNER JOIN timesheet_tasks AS tsks ON ts.task_ref = tsks.task_ref 
INNER JOIN timesheet_task_groupings AS grps ON tsks.grouping_ref = grps.grouping_ref 
INNER JOIN timesheet_sites AS sits ON ts.site_ref = sits.site_ref 
INNER JOIN vw_staff_members AS sm ON ts.staff_member_ref = sm.staff_member_ref
--INNER JOIN week_list AS WL ON ts.timesheet_ref = WL.week_ref

--WHERE (ts.status IN (1, 2)) AND (cat.is_leave_category = 0)
--AND WL.week_ref=@week_ref AND WL.start_week BETWEEN ts.start_dtm AND ts.end_dtm

WHERE @weekDate <= convert(datetime, end_dtm, 120) 
AND @weekDate > convert(datetime, start_dtm, 120)



GROUP BY ts.staff_member_ref, sm.common_name, sm.department_name, DATENAME(MONTH, ts.start_dtm), DATENAME(YEAR, ts.start_dtm), ts.timesheet_cat_ref, 
                      cat.desc_long, grps.grouping_ref, grps.description, ts.status, ts.booked_time, ts.task_ref, tsks.task_code, tsks.description, ts.site_ref, sits.description, ts.start_dtm, 
                      ts.end_dtm
ORDER BY sm.common_name, timesheet_cat_desc, tsks.task_code, site_desc
  • 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-31T20:16:39+00:00Added an answer on May 31, 2026 at 8:16 pm

    I think you actually want:

    DECLARE @testDate date
    SET @testDate=dateadd(wk, 5804, 0)
    --SET @testDate='2011-03-28 00:00:00.000'
    
    SELECT *
    FROM dbo.timesheets
    WHERE @testDate <= convert(datetime, end_dtm, 120) and 
          dateadd(wk, 1, @testDate) > convert(datetime, start_dtm, 120)
    
    PRINT @testDate
    

    This version of the query tests whether any part of the records’ date ranges is within the week beginning on @testDate.

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

Sidebar

Related Questions

I have the following code: DECLARE @monthPassed VARCHAR(MAX) SET @monthPassed = '2010' DECLARE @yearPassed
I have following tsql code in sql server 2008: declare @ID INT SET @ID
I have following code in my application: // to set tip - photo in
I have the following code in a stored procedure. .... select ... into #temp
I have the following code: DECLARE @temp_table_1 TABLE (id int identity(0, 1), col_1 varchar(50)),
I have the following code: #include<stdio.h> int main() { int(* a)[10]; //declare a as
I have the following t-sql code which I have converted to c#. DECLARE @guidRegular
I have the following code and it works good: var _data = (from qu
I have the following code which works fine and returns the expected results: DECLARE
I have the following T-SQL code: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION T1_Test

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.