Jeff Voss
Jeff Voss

Reputation: 3695

PHP date is one day ahead?

when I write <?php echo date('d'); ?> the day is always one day ahead? I've checked everything and it doesn't echo that on my other websites on the same database

Upvotes: 0

Views: 3179

Answers (3)

kylex
kylex

Reputation: 14406

The database may be the same, but the server is most likely different. The date is pulled from the hosting server.

A quick fix is to set date_default_timezone_set()

Your other option, if you are hosting your own site, is to fix the date time settings on the server itself.

Upvotes: 2

Shad
Shad

Reputation: 15451

You need to set date_default_timezone_set(). Your server time is one day different from where you actually are.

http://php.net/manual/en/function.date-default-timezone-set.php

Upvotes: 2

wpearse
wpearse

Reputation: 2422

Try setting the timezone to one of these values.

For example, try this at the start of your script (with the appropriate timezone, of course):

<?php date_default_timezone_set('Pacific/Auckland'); ?>

Upvotes: 4

Related Questions