Query in date column with current week filter

Asked

Viewed 219 times

1

I’ve been looking for a mysql command that does such a function. The purpose of this is that I have to display a current week’s item schedule. From Sunday to Saturday. Is there a query that makes this filter ? Well the column is date, Y-m-d.

  • Have you tried using WEEK()? Connect to this https://stackoverflow.com/questions/6710342/mysql-grouping-by-week

  • Yes, but she won’t return any record to me

1 answer

3


Use the function YEARWEEK together with the CURDATE:

SELECT *
  FROM tabela
 WHERE YEAR(data) = YEAR(CURDATE())
   AND YEARWEEK(data, 1) = YEARWEEK(CURDATE(), 1)

YEAR

Returns the year for date, in the range 1000 to 9999, or 0 for the "zero" date.

In free translation:

Returns the year of a date, in a range from 1000 to 9999, or 0 for the date "zero".


YEARWEEK

Returns year and week for a date.

In free translation:

Returns the year and week of a date.


CURDATE

Returns the Current date as a value in 'YYYY-MM-DD' or YYYYMMDD format, Depending on whether the Function is used in a string or Numeric context.

In free translation:

Returns the current date as the value in the format 'YYYY-MM-DD' or YYYYMMDD, depending on the context in which the function is used (string or numeric).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.