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

Dallas Freeman
Dallas Freeman
3,637 Points

Code works. Challenge disagrees.

Here's the 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

Here's the code:

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

(I copied and pasted the code as it was, but here it displays all on one line when I post it. Don't know why, or how to change that.)

Here's the previewed result: Today is August 24, 2016

Error says: Bummer! You have not passed the correct string for formatting

This is the second time in this new PHP course that a challenge has taken issue with perfectly functional code, and not provided a helpful tip to tell me what I'm doing wrong. So I hit a brick wall.

3 Answers

Hi Dallas,

The problem is that you are using j for date format.

If we take a look at http://php.net/manual/en/function.date.php you can see that j returns - Day of the month without leading zeros so this would return 1-31 when the challenge wants you to turn it with a leading 0.

This would require you to use

<?php
echo date("F d, Y");
?>
Dallas Freeman
Dallas Freeman
3,637 Points

Apologies. That was in the code I showed there, but it's not what i have tried in the challenge. I have been using d.

Can you add the code you are using here? I just tested this challenge using the code I added above and it works fine.

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

Hi there! I honestly don't know what's wrong. I found the challenge here. If I open up that challenge and copy/paste the original code you posted .. it works, even without the period at the end of the string as suggested by Jason Anders.

My best guess here is that it might be something with your web browser. I suggest trying your code in the same challenge from a different web browser and see what happens!

Hope this helps! :sparkles:

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Dallas,

You didn't link to the challenge, so I can't test my answer. However, if I remember correctly the string the challenge wants returned includes a period at the end, which yours is missing.

Challenges are very picky and often check for a very specific return. Just use concatenation to add a period.

I also added the markdown to your post so your code snippet is readable in the forum. Please have a look at the Markdown Cheatsheet (link will be above the Post button) to see how to post code in the forum.

Keep Coding! :) :dizzy: