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 PHP Basics PHP on the Web Combining Multiple Files with Includes

Aaron Coursolle
Aaron Coursolle
18,014 Points

Preview 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.

Aaron Coursolle
Aaron Coursolle
18,014 Points

Tried this too:

<?php
echo 'Today is ';
//Place your code below this comment
echo date('F d' . "\," . ' Y');
?>

Link: https://teamtreehouse.com/library/php-basics-2/php-on-the-web/date-function

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

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
Aaron Coursolle
18,014 Points

Thank you. You helped me reach my PHP learning goal I had planned for Friday/Saturday.

To 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
Juan Ignacio Lambardi
3,943 Points
<?php
echo 'Today is  ';
echo date('F d, Y');
?>
Juan Ignacio Lambardi
Juan Ignacio Lambardi
3,943 Points

This should work. You can 'echo' the date function directly, not being necessary to write again the first part! :)