get all records added in last 3 days

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

get all records added in last 3 days

Post by amir »

ive got a slight issue where im facing to display all records that were added in the last 3 days from the current date.

our table contains a field called joined and i store a date value in it like:

Code: Select all

$joined = date('F j, Y, g:i a');
so what date functions would i use to display all records in the last 3 days?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Take a look at the mysql date and time functions:

http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html

The very first example should help you

Code: Select all

mysql> SELECT something FROM tbl_name
    -> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Bear in mind that the newer (and more useful) date functions in MySQL are only available as of 4.1 (in some cases, 4.0, but almost none of the good ones are in 3.23).
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Thanks guys!

I got it working...
Post Reply