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 trialAaron Coursolle
18,014 PointsPreview is showing expected output but can't pass challenge.
Once again, the button attached to the Challenge (for posting to the forum) is non-responsive. So that's why this question is located here.
Here is one way I attempted:
<?php
echo 'Today is ';
//Place your code below this comment
echo date('F d\, Y');
?>
error message
You have not passed the correct string for formatting
In the challenge I am asked to include a leading zero, but the only thing in the documentation that matches that request,--provides a leading zero--is when the date is single digit. Otherwise the date is two digits with no leading zero == ('d').
Here is another attempt. Closer to the way done in the video:
<?php
echo 'Today is ' . date('F d\, Y');
?>
error message is something like this:
no echo found
I am lost as to why my code is not passing.
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! The problem lies in the backslash that you've put in. It's not required here. Remove the backslash from the very first code that you posted and it should pass! Good luck!
edited for additional comment
The reason you received this:
Bummer! You have not passed the correct string for formatting
is because they're not checking your output. They're checking the string that you send to the date method. And because yours has a backslash it's causing it to fail although the output is still correct.
Aaron Coursolle
18,014 PointsThank you. You helped me reach my PHP learning goal I had planned for Friday/Saturday.
Sean Habel
4,407 PointsTo piggy back off of what Jennifer answered and to give a little more explanation, you may have thought to use the backslash thinking that a comma is a special character that needs to be escaped. However in PHP commas can be used inside Strings without having to "escape" them!
Juan Ignacio Lambardi
3,943 Points<?php
echo 'Today is ';
echo date('F d, Y');
?>
Juan Ignacio Lambardi
3,943 PointsThis should work. You can 'echo' the date function directly, not being necessary to write again the first part! :)
Aaron Coursolle
18,014 PointsAaron Coursolle
18,014 PointsTried this too:
Link: https://teamtreehouse.com/library/php-basics-2/php-on-the-web/date-function