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 trialKristofer Doman
18,307 PointsSecond time today I have a question which appears to give false errors to the user, thanks Treehouse.
Bummer! Make sure you return true for a valid date. Remember the function checkdate returns true if valid and false if not.
Well through all my testing, as you can use the code below. True appears to be returned when the date is valid, and false appears to come through when it's not. What am I doing wrong now Treehouse? What is the mystery error now?
<?php
echo (valid_sql_date('2011-10-10')) ? 'True' : 'False';
function valid_sql_date($date) {
//add code here
$dateMatch = explode('-', $date);
if (count($dateMatch) != 3 ||
strlen($dateMatch[0]) != 4 ||
strlen($dateMatch[1]) != 2 ||
strlen($dateMatch[2]) != 2 ||
!checkdate($dateMatch[2], $dateMatch[1], $dateMatch[0])) {
return false;
}
return true;
}
1 Answer
Kristofer Doman
18,307 PointsNope, it gives me the same error: Bummer! Make sure you return true for a valid date. Remember the function checkdate returns true if valid and false if not.
Thanks for trying though!
Ben Payne
1,464 PointsJust noticed the indexes are wrong. Switch the 2 and the 1:
return checkdate($dateMatch[1], $dateMatch[2], $dateMatch[0]);
Sorry about that.
-Ben
Ben Payne
1,464 PointsBen Payne
1,464 PointsTry this:
-Ben