00 Votes

MySQL: Read out Records of last Week

Question by Compi | 2016-04-24 at 17:05

I am searching for a possibility to read out all data sets from my MySQL database which are not older than one week.

Each record has a TIMESTAMP column named "dat" in which the date of the entry is written. I have to compare this column with the date before one week, I think. Is this possible somehow?

ReplyPositiveNegative
0Best Answer0 Votes

Of course, that is possible.

You can just use the following query for that:

SELECT * FROM tab WHERE dat > NOW() - INTERVAL 1 WEEK;

Or you can also use this:

SELECT * FROM tab WHERE dat < DATE_SUB(NOW(), INTERVAL 1 WEEK);

Instead of writing "INTERVAL 1 WEEK" you can also write "INTERVAL 7 DAY" to get the same result.
2016-04-25 at 19:05

ReplyPositive Negative
Reply

Related Topics

PHP: Determine Week Number

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.