Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Karan Jindal
PLUS
Karan Jindal
Courses Plus Student 1,406 Points

How to filter content on a page date wise?

Hi, I want to know: How to filter content on the basis date , month and year where the data is being fetched from the database.

Karan Jindal
Karan Jindal
Courses Plus Student 1,406 Points

You can take the example of billing system where we choose specific date and the results are displayed accordingly.

1 Answer

Logan R
Logan R
22,989 Points

I would suggest storing the date as a time() [http://php.net/manual/en/function.time.php] and sorting the SQL by time.

SQL is rusty, but something like:

Select date from table
ORDER BY date ASC

Edit: A link that provides an extended answer: http://www.w3schools.com/sql/sql_orderby.asp

You can convert time() into a date using the date() [http://php.net/manual/en/function.date.php] function.

string date ( string $format [, int $timestamp = time() ] )

date("d m y", 78299428934);