3 Replies - 166 Views - Last Post: 24 March 2019 - 08:29 AM

#1 juniordev101   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-March 19

MYsql Getting last week of data based on current date

Posted 24 March 2019 - 07:33 AM

I want to be able to retrieve the last week of data (Mon - Sun)
It needs to be able to work based on the currentDate, i.e. today is 24/03/2019 so in this case
it needs to display the 11/03/2019 - 17/03/2019 and so on
This is my code:

SELECT *
FROM TABLE
WHERE date_time <= DATE_SUB(DATE(NOW()), INTERVAL DAYOFWEEK(NOW())+6 DAY) AND date_time < DATE_SUB(DATE(NOW()), INTERVAL DAYOFWEEK(NOW()) - 1 DAY) 




Thanks in Advance !!

Is This A Good Question/Topic? 0
  • +

Replies To: MYsql Getting last week of data based on current date

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15111
  • View blog
  • Posts: 60,452
  • Joined: 12-June 08

Re: MYsql Getting last week of data based on current date

Posted 24 March 2019 - 08:18 AM

Is there a question?
Was This Post Helpful? 0
  • +
  • -

#3 juniordev101   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-March 19

Re: MYsql Getting last week of data based on current date

Posted 24 March 2019 - 08:24 AM

Yes, the above code doesnt work dynamically, how can i fix this ?????
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15111
  • View blog
  • Posts: 60,452
  • Joined: 12-June 08

Re: MYsql Getting last week of data based on current date

Posted 24 March 2019 - 08:29 AM

Why is your 'interval' not just a number?

DAYOFWEEK(NOW())+6


doesn't make much sense.. why not just a '6'?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1