Jump to content

Suspected leap year problem with "created" variable


PHPSpert
 Share

Recommended Posts

I'm having a problem with incorrect "created" dates.

"created" dates are showing one day ahead. I don't think it's the server because I did a echo date("Y") and it shows the correct date. I'm doing this echo date("Y m d", $page->created); to show the page/article date.

The timezone is set to New York time, which is fine as it's close enough.

I'm wondering if this problem is coming up because it's a leap year. I didn't want to fish around the core to find out how "created" was set after looking around and not being able to find it.

Anyone have any thoughts on this, or how to fix it?

Link to comment
Share on other sites

The 'created' field is set from a MySQL 'NOW()' command (current timestamp), rather than from ProcessWire or PHP. I would guess that your MySQL may be configured for a different timezone? I've not seen this difference before. Try this in a MySQL client (like PhpMyAdmin):

SHOW VARIABLES LIKE  '%time_zone%'

Based on your NY timezone, it should say this:

system_time_zone EST
time_zone SYSTEM
Link to comment
Share on other sites

  • 3 years later...

First of all, thank you Ryan and the ProcessWire community for creating such an amazing framework!

I've run into a similar problem with a site for an overseas client. The client is based in London, so I set the $config->timezone setting to 'Europe/London'. However, the server the site is hosted on is on the US East Coast. Whenever I edit a page in the back-end, the "Modified" date gets set to the current time of the server, and it will say it was edited "4 hrs ago", even though it should really say less than a minute ago.

Maybe I'm misunderstanding how the $config->timezone should be set. Should this always be set to the same timezone as the server, regardless of where the client/organization is located? I don't believe I can change the timezone for the MySQL server, since the site is on a shared host.

Link to comment
Share on other sites

Change your timezone in your .htaccess file orEnsure that your MySQL config has the right timezone setting, even on a shared hosting you should have access to PhpMyAdmin or an equivalent (You should definitely work with your hosting provider)

Link to comment
Share on other sites

Thanks for the reply.

I did some more research on this issue and there is apparently a MySQL command that you can use to set the default timezone on a per session basis:

SET time_zone='offset';

The 'offset' represents the difference to UTC/GMT, so in my case it would have to be set to '+0:00'.

I can run this command in phpMyAdmin and it works fine. However, I'm not sure how/where to inject this bit of code into my ProcessWire site. It has to run on every page request before any queries take place. Is there a hook or some other way to achieve this?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...