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

Tessa Askamp
Tessa Askamp
4,400 Points

Help with PHP assingment setting the date. Terminal says I'm right but if I check the task, it is said to be wrong

The task is: set the date to the following example: Today is July 10th, 2016. So I wrote in PHP:

<?php

echo 'Today is ' . date("F j, Y") . ". "; //Place your code below this comment

?>

When I check, the output is correct, but I keep on failing the assignment. Can someone help me out?

Btw, I tried multiple ways, also for example:

<?php

$today = date("F j, Y"); echo 'Today is ' . $today; //Place your code below this comment

?>

It keeps on telling me that 'It looks like I forgot to echo'

index.php
<?php

echo 'Today is ' . date("F j, Y");
//Place your code below this comment

?>

2 Answers

andren
andren
28,558 Points

There are two issues, one caused by the code checker being stubborn about how the code should be laid out and one actually caused by your format string being slightly wrong.

The first issue is that this challenge does not want you to add the date directly to the first echo statement, but to instead add your own echo statement below it. You have to do this to complete the challenge, even though the resulting string won't look any different either way.

The second issue is caused by the fact that while your date formatting is very close to the requested format it is in fact not entirely correct. The code challenge states that the day is formatted as such: "day of the month with leading 0". Your formatted date does not have leading zeros for single digit days.

For days with a leading single digit you use d instead of j.

Fixing those two issues like this:

<?php

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

Will allow your code to pass the challenge.

Tessa Askamp
Tessa Askamp
4,400 Points

Thank you! The d I indeed already figured out, and now I passed the assignment, thanks!