Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Reading and Writing Reports Naming Reports

Nathan LaBrake
Nathan LaBrake
24,088 Points

This project's (including .zip file) date functionality doesn't work how it should.

I downloaded the .zip file included by Treehouse and did a test upload to my server.

I noticed that the sort by date functionality doesn't work quite right. It's August 2017 now and if I click "Last Week," it returns results that includes reports from August 2016... Which would have been last week last year.

This means somehow Alena's code isn't detecting the year. It seems to detect only based on the month - which is weird.

And no, this isn't my code - this is upon testing the code that Treehouse uploaded - which would have "worked" last year, but not this year.

Any fixes for this? Apparently we need to adjust something in the strtotime() function.

Nathan

1 Answer

Niki Molnar
Niki Molnar
25,698 Points

I'm not sure which version you've downloaded but my final reports.php page had the following in the select, which works fine, if it's any help.

<optgroup label="Date">
    <option value="date:<?php echo date("Y-m-d", strtotime("-2 Sunday")) ?>:<?php echo date("Y-m-d", strtotime("-1 Saturday")) ?>">Last Week</option>
    <option value="date:<?php echo date("Y-m-d", strtotime("-1 Sunday")) ?>:<?php echo date("Y-m-d") ?>">This Week</option>
    <option value="date:<?php echo date("Y-m-d", strtotime("first day of last month")) ?>:<?php echo date("Y-m-d", strtotime("last day of last month")) ?>">Last Month</option>
    <option value="date:<?php echo date("Y-m-d", strtotime("first day of this month")) ?>:<?php echo date("Y-m-d") ?>">This Month</option>
</optgroup>