Jump to content

Archived

This topic is now archived and is closed to further replies.

acidglitter

help with mysql queries and dates...

Recommended Posts

How can I only show things from a table that are at least one month old? The row or whatever that shows the dates is the "date" type

Share this post


Link to post
Share on other sites
SELECT something FROM tbl_name WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY)

Share this post


Link to post
Share on other sites
So I tried that and I changed everything except for
WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY)

Instead of limiting what it showed to things that are at least a month old, it just showed EvEryThiNG :(

Share this post


Link to post
Share on other sites
[b]redarrow[/b]'s example, from [url=http://www.mysql.org/doc/refman/4.1/en/date-and-time-functions.html]MySQL.org[/url], is missing a comparison. Otherwise, it should work fine. Try this:

[code]
<?php

$query = "SELECT something FROM tbl_name WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col";

?>
[/code]

Share this post


Link to post
Share on other sites
gr this is irritating..

So it looks like this now
[code]$sql=mysql_query("SELECT * FROM losers WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= lastused");[/code]

Maybe I should just select everything and then put LIMIT TO something..?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.