Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics PHP on the Web Date Function

Jennifer Klakulak
Jennifer Klakulak
1,004 Points

I think I am stuck somehow on the SINGLE date function. What I currently have was my original thought, but nope

I originally put my current code in and it worked on the preview. But when I check work, it tells me that it is not correct. I have tried every form of what I believe to be the SINGLE date function. I read through the documentation. I tried timestamp. I am stuck.

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

2 Answers

jonathanbarrios
STAFF
jonathanbarrios
Treehouse Teacher

👋 Hi Jennifer,

The problem here is the whitespace in between the date function and the parenthesis. Just remove the white space and this should work:

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

This can be confusing because the documentation looks like it has whitespace in the description:

date ( string $format [, int $timestamp = time() ] ) : string

But if you scroll down and look at the examples, they do not have whitespace.

<?php
// Prints something like: Monday
echo date("l");

// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

/* use the constants in the format parameter */
// prints something like: Wed, 25 Sep 2013 15:28:57 -0700
echo date(DATE_RFC2822);

// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>

I hope this helps and happy coding! 🙌

Jennifer Klakulak
Jennifer Klakulak
1,004 Points

It was the white space between date and parenthesis and the double quotes in front of date. I had to take out everything between the first quotes and the d on date. Then it worked. It looked like it was working before, the quiz just wanted it cleaned up. Thank you.