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 Let PHP Do the Work

Karen Fletcher
Karen Fletcher
19,189 Points

Error when using date() function: "Warning: date()"

I'm running into issues getting the Date to display when using the date function. The following error appears, followed by the correct date:

"Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /Users/me/where/my files/live/index.php on line 39"

Here is my code:

<section class="footer text-center">
      &copy; <?php echo date('Y'); echo " " . $display_name;
      echo ". Last modified: " . date ("F d Y H:i:s.", getlastmod()); 
      ?>
   </section>

Any help would be greatly appreciated!

Karen Fletcher
Karen Fletcher
19,189 Points

Based on information I found on stackOverflow, I also tried adding the following code block to the top of my index.php since I can't edit the php.ini file directly, but I still get the same error.

<?php
if ( ! ini_get('date.timezone') ) {
    date_default_timezone_set('Central');
}
 ?>