Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Filter recordset by date interval?

New Here ,
Oct 15, 2011 Oct 15, 2011

I have a php page that displays "orders" from a mySql database. Each order has a field named "weekof" which represents the week during which it will be processed. The value for this field is the date of the monday of that week in m/d/Y format. I want to filter the record set so that when the date() is within the interval of moday to sunday all the records for that week will be displayed. Any idea of where to go or how to possibly do this is greatly appreciated. If I didn't explain the problem well enough please let me know and I will try to clear up whatever I can. Thanks again...

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 15, 2011 Oct 15, 2011

Try:

Select * from MyTable where DATE_FORMAT(weekof, '%x %v') = Date_FORMAT (CURDATE(), '%x %v')


Translate
LEGEND ,
Oct 15, 2011 Oct 15, 2011

Try:

Select * from MyTable where DATE_FORMAT(weekof, '%x %v') = Date_FORMAT (CURDATE(), '%x %v')


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2011 Oct 17, 2011

That worked great thanks so much for the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2011 Oct 18, 2011

Thanks again for that function, I just had one question about it. I am dispalying 3 separate weeks on this page the first is the current week so I used the exact code you posted... The 2nd is "next" week so I did the following:

where DATE_FORMAT(weekof, '%x %v') = Date_FORMAT (CURDATE()+7, '%x %v')

That worked great as well. The 3rd week is "two weeks from now" so I did the following...

where DATE_FORMAT(weekof, '%x %v') = Date_FORMAT (CURDATE()+14, '%x %v')

For some reason this one isn't wokring... If I set it back a week to just "+7" then it displayes "next week" as expected however when 14 days are added it shows no results for some reason... Do I need to format something different to go 2 weeks into the future?

Thanks for all your help.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 18, 2011 Oct 18, 2011

>CURDATE()+14

To be honest, I'm not sure what value is produced when adding a value to a date in that manner. If you want to do date math, use one of the date math functions. Use ADDDATE() or DATEADD().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2011 Oct 19, 2011
LATEST

Thanks again... Used a DATE_ADD() funtion inside the DATE_FORMAT() function and it works perfectly now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines