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 trialBrian Thomas
10,688 PointsAm I using the checkdate function correctly?
Unsure of what I could be doing wrong.
<?php
$date = '2017-01-01';
$date = explode('-', $date);
//var_dump($date);
function valid_sql_date($date) {
//add code here
if(count($date) != 3
|| strlen($date[0]) != 4
|| strlen($date[1]) != 2
|| strlen($date[2]) !=2
|| checkdate($date[0], $date[1], $date[2])
) {
//echo $date;
return false;
}
else
{
var_dump($date);
//echo $date;
return true;
}
};
//var dump returns the $date variable that is set before the function
var_dump(valid_sql_date($date));
/*
the code seems to follow the explode method and if statement but
when setting a var dump or echo to the $date variable within the if statement
to troubleshoot it returns '2016/31/08' while also out putting true and the correct
variable assignment in the else
*/
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Brian Thomas ! It looks like you're off to a great start. There are a couple of things going on here. First, you're meant to be checking if checkdate
does not return a true
so you will need !checkdate()
.
Secondly, that $datematch
contains the year, month, and day in that order. But checkdate
requires that you send in the month, day and year in that order. This means that you will need a !checkdate($datematch[1], $datematch[2], $datematch[0])
because the year should come last
Hope this helps!
edited for additional information: For the purposes of challenges you should refrain from making any variables or executable code outside the function. It can cause the challenge to fail. Right now, you are overwriting the data that Treehouse is sending in from the challenge by setting your own $date
. You will also need to remove the call to the function and any and all var_dump
s you have.
Brian Thomas
10,688 PointsBrian Thomas
10,688 Pointsπ€πthank you