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 trialAlex Hughes
4,728 PointsI Don't Understand How This Isn't The Answer
Hi, could anyone explain to me what this question is actually asking? I've done what the question wants, and it won't pass, or tell me why it's not passing.
The Question: When saving a date in a 'date' field, you need make sure the date is formatted properly. The correct format is YYYY-MM-DD.
Complete the function to convert a passed date into a SQL safe date and return the results using the following requirements:
Use the date() function to properly format the passed date. Use the strtotime() function to accept anything from a date in a different format to a string like 'yesterday'.
My Code:
function convert_date_sql($date) {
//add your code here
return date('Y/m/d', strtotime($date));
}
<?php
function convert_date_sql($date) {
//add your code here
return date('Y/m/d', strtotime($date));
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHi Alex,
Your syntax is correct, but your formatting is not. Challenges are very specific and picky. Here, the instructions clearly state that:
The correct format is YYYY-MM-DD.
But you are formatting it as YYYY/MM/DD. Notice, the instructions wants dashes, and you are using slashes. Once that's corrected, the code passes.
Other than that, nice job! :)
Ryan Richard
15,476 PointsRyan Richard
15,476 PointsGreat work, to add to what Jason said, you are missing the closing of the PHP code block. That might have got copied over incorrectly but that could the next error if you try that the new formatting.
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHi Ryan Richard
The closing tag actually wasn't missed in the copy/paste. When the code file is pure PHP, the closing tag is not needed. In fact, the preferred syntax, according to the PHP Documentation is to omit the closing tag with pure PHP files.
Either will compile and would be correct syntax, but the convention is to have no closing tag.
Keep Coding! :)