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 Date Function

John Driscoll
John Driscoll
20,646 Points

Cant get echo date coding challenge to work - in php basics

I'm stuck on this coding challenge:

"For this code challenge, you'll need to check out the documentation for the date function to see details about formatting. Use the date function to add todays date to the display message in the following format: full month, day of the month with leading 0, comma and 4 digit year. Example: Today is July 04, 2016"

I've tried:

<?php

echo 'Today is ';

//Place your code below this comment echo date('F d\, Y');

?>

but the editor gives me an error saying I haven't created the correct string. Can anyone tell me where I'm going wrong?

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

4 Answers

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

Hi there! This challenge is specifically testing the string inside the date function. And if it doesn't match exactly what they have it will fail. In your case, you've included a backslash which is causing the problem If you remove that, your code passes!

echo date('F d, Y');

Good luck! :sparkles:

Darrell Conklin
Darrell Conklin
22,099 Points

I think I kind of understand why you may have thought you needed to escape the comma thinking that the date() function might have misinterpreted the string because commas weren't on the list of string parameters that it accepts but just below the format parameter string list it reads "Unrecognized characters in the format string will be printed as-is." so no escapes were necessary.

You would only need to escape a character that the function recognized as a parameter so you could use it as-is instead.

John Driscoll
John Driscoll
20,646 Points

Thank you Jennifer, I thought I needed to use the \ as an escape character but obviously not.

Aaron Uusitalo
Aaron Uusitalo
4,405 Points

I had the exact same issue with it. It's a bit frustrating and pedantic. They should be testing the output of the code, and if you achieve it in a slightly different way you should not be penalized.

Especially since the official PHP documentation that they link to specifically shows the use of an escape character ("backslash") in the example that most closely resembles the goal of the exercise.