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 Build a Simple PHP Application Creating the Menu and Footer Introducing Conditionals

M Minnix
M Minnix
5,179 Points

How do you manage relative time/date? Is it an issue at all?

In a circumstance like this (PHP code within a web page), where does the time/date come from that gets referenced? On the user's PC or from the server (possibly on other side of the world)?

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Matthew,

The date and time is referenced from the server, by default PHP will automatically look at the timezone file on the server (if any) otherwise use the specified timezone location if one is set in the php.ini file.

Zac Mackey
Zac Mackey
11,392 Points

To add a bit to this question (since I had a similar one):

If you are trying out the code listed in the PHP Introducing Conditionals video to echo a message based on the time, you should first set the timezone in your PHP code, i.e.

date_default_timezone_set('America/Chicago');

The above example is my use case since I'm located in the Central timezone. This provided the correct time and therefore the correct echo.

M Minnix
M Minnix
5,179 Points

Thanks. The example in the tutorial builds a conditional check w/PHP to echo out "Good Morning" "Good Afternoon" etc, depending on time date("G")... so, as is and in standard configurations (which is the case for most of us learning on generic hosting accounts), you're saying it'll say Good Morning (or whatever) according the server's point of view (and thus, likely), wrong to the receiver?

Chris Shaw
Chris Shaw
26,676 Points

In a nutshell, yes. You can change this programatically by using the DateTime class which was introduced in PHP 5.3.

http://php.net/manual/en/datetime.settimezone.php