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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:18:07+00:00 2026-05-23T21:18:07+00:00

I have a report that is driven by a sql query that looks like

  • 0

I have a report that is driven by a sql query that looks like this:

   SELECT batch_log.userid,
         batches.operation_id,
         SUM(TIME_TO_SEC(ramses.batch_log.time_elapsed)),
         SUM(ramses.tasks.estimated_nonrecurring + ramses.tasks.estimated_recurring),
         DATE(start_time)
    FROM batch_log
    JOIN batches ON batch_log.batch_id=batches.id
    JOIN ramses.tasks ON ramses.batch_log.batch_id=ramses.tasks.batch_id
    JOIN protocase.tblusers on ramses.batch_log.userid = protocase.tblusers.userid
   WHERE DATE(ramses.batch_log.start_time) > "2011-02-01" 
     AND ramses.batch_log.time_elapsed > "00:03:00" 
     AND DATE(ramses.batch_log.start_time) < now() 
     AND protocase.tblusers.active = 1
     AND protocase.tblusers.userid NOT in ("ksnow","smanning", "dstapleton")
GROUP BY userid, batches.operation_id, date(start_time)
ORDER BY start_time, userid ASC

Since this is to be compared with the time from the current payperiod it causes an error.
Our pay periods start on a Sunday, the first pay period was 2011-02-01 and our last pay period started the 4th of this month. How do I put that into my where statement to strip the most recent pay period out of the query?

EDIT: So now I’m using date_sub(now(), INTERVAL 2 WEEK) but I really need a particular day of the week(SUNDAY) since it is wednesday it’s chopping it off at wednesday.

  • 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-23T21:18:08+00:00Added an answer on May 23, 2026 at 9:18 pm

    You want to use DATE_SUB, and as an example.

    Specifically:

    select DATE_SUB(curdate(), INTERVAL 2 WEEK)
    

    gets you two weeks ago. Insert the DATE_SUB … part into your sql and you’re good to go.

    Edit per your comment:

    Check out DAYOFWEEK:

    and you can do something along the lines of:

    DATE_SUB(DATE_SUB(curdate(), INTERVAL 2 WEEK), INTERVAL 2 + DAYOFWEEK(curdate()) DAY)
    

    (I don’t have a MySql instance to test it on .. but essentially subtract the number of days after Monday.)

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

Sidebar

Related Questions

I have a SQL Report driven by a query that sorts it in ascending
I have a report that uses User!UserID. But Data Driven Subscription cannot be created
I have a report that I created with Crystal Reports 2008. This report uses
scenario: I have difficulty in building a single query that would display a report
I have a report that uses a TChart that I am maintaining. One of
I have a report that renders data returned from a stored procedure. Using profiler
I have a report that is used by a windows service and a form
I have a report that takes two parameters from a couple of text boxes
I have a report that calculates multiple date differences (in business days, not DATEDIFF)
I have a report that I'm exporting to PDF using the VS2008 version of

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.