Jump to content
PHPSpert

Suspected leap year problem with "created" variable

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks Ryan,

That's the problem exactly. It's using a different timezone for the MySQL database.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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)

Share this post


Link to post
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?

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Markus (Blue Tomato)
      I'am working on a migration script from the ImageExtra Module to the new Custom Image Fields feature in ProcessWire.
      I have some problems while setting a field value to the new custom image field. I have set up the custom field and it works correct in the admin panel but not via the API:
      $page->images->my_custom_image_field = "test"; $page->save(); Results into:
      Fatal error: Uncaught ProcessWire\WireException: Item 'my_custom_image_field' set to ProcessWire\Pageimages is not an allowed type in /var/www/html/wire/core/WireArray.php:458
       
       
    • By Peter Troeger
      Hello 🙂
      I have set up pagination on a mulitlanguage site.
      I've done this before, but this time I have a problem I can't solve.
      Pagination is activated on 'parent-template' and 'child-template' just to be sure 🙂
      This is my code:
      $children = $page->children('limit=1'); foreach($children as $child) { $title = $child->title; echo $title; } echo $children->renderPager(); The navigation is output correctly and the link look correct as well 'parent-page/page2/'.
      But when I click the link, the site seems to redirect back to 'parent-page/
      Any help would be greatly appreciated 🙂
      - Peter
    • By Jens Martsch - dotnetic
      Hi guys I need an estimate for the following task:
      I developed a job candidate application in ProcessWire and need an extension to a Lister Pro Page.
      My customer wants to display a summary table of the filtered data like in the attached screenshot.
      When you filtered the view, that summary should show how many candidates have which status according to the actual filtered view.
      If you change the filter, the summary table has to be updated also.
      Who can accomplish this task and what would it cost?
      I first need an estimate to tell it to my customer. If he says the price is ok I will provide you with FTP Data to a dev server version of  that tool.
      Thank you in advance.

    • By LuisM
      Hi there,
      im a bit lost right now. I added an hook after templates::save which should get the affected template and write its template ID into a JSON.
      The problem is, the event->object gives me an instance of the templates class. How can I narrow this down to the saved Template and get its ID and fieldgroup?
    • By Clément Lambelet
      Hey!
      I've been working on a Processwire installation (3.0.123) for a few days now and I must have made a big mistake this morning because the links in the admin's main menu no longer appear.
      This is not related to the admin theme, because the bug occurs with all themes (Default, Reno, Uikit).
      I tried to reinstall with the dev version (3.0.136), but the problem is still there. I also uninstalled all the modules I had added, without success. There is no error in the js console. 
      I still can access/view/edit the pages  by going through the admin/page list.
      Thanks in advance for your help!


×
×
  • Create New...