0

I'm working on a project where I want to display data after 3 days have passed.

What I'm having an issue with is getting the current date dynamically in php/sql. I'm aware of how to get the current date in php, but I dont know how to compare that value to the date that I have in the sql database.

Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
  • 2
    The docs would be a good place to start... http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html mysql has a zillion useful date/time functions. – Marc B Jan 03 '13 at 18:53

3 Answers3

1

You can do that directly in SQL

select * from your_table
where date_column <= curdate() - interval 3 day
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

You can use an interval select to limit the records to within 3 days if the column you're checking istimestamp, date, or datetime.

select * from tablename where timestamp_column >= NOW() - INTERVAL 3 DAY
Ray
  • 40,256
  • 21
  • 101
  • 138
0

You can use DATEDIFF function to check for days.

SELECT * 
FROM tablename
WHERE DATEDIFF(CURRENT_DATE(), datecol) >= 3;
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83