• Resolved webtent

    (@webtent)


    I set the Timezone under Settings -> General to ‘New York’ and still getting UTC timestamps in the database. I tracked this down to the settings in wp-settings.php of:

    date_default_timezone_set( ‘UTC’ )

    I changed to ‘America/New York’ and all posts to the db now in eastern time as I need. I am fairly new at using WP, is it okay to change this setting?

Viewing 3 replies - 1 through 3 (of 3 total)
  • No, you should never change the core code of WordPress because it will get wiped out the next time you update it.

    WordPress stores the dates in two fields:

    post_date – The date that you have set in Settings -> General -> Timezone
    post_date_gmt – The UTC/GMT date

    The reason is that in the case that you change the site’s timezone, you’ll be able to recalculate the correct date.

    By changing the entire site’s default timezone, which sets the post_date_gmt column, the dates of your new posts will be saved incorrectly.

    If you change Settings -> General -> Timezone AFTER you have created posts and pages, those old posts and pages will NOT be updated to the new timezone. You will need to open up each one and click the Update button.

    Thread Starter webtent

    (@webtent)

    Thanks for that info, still trying to get my head around it all to make sure I understand correctly how it affects our database. We are getting ready to go live with a new website with 12K+ migrated records from a ruby application. I asked the design company about this setting being UTC in the General -> Settings -> Timezone and no one address during the initial migration about a month ago. A few days ago, they did another migration, but after which I changed that setting to ‘America/New York’ after asking them again if there was any problem doing so and they said no. This was a concern of mine since we had experienced issues with the Ruby app using all UTC even at the server level. The server timezone for this new WP website is Eastern and I thought it best WP was set to the same.

    Now, doing a query on the wp_posts table, I see the two different dates as you mention until we get back a week or so, then both fields, post_date and post_date_gmt, are the same. I do know the second migration did an update and not overwrite already migrated data. Since the initial migration was done when both General -> Settings -> Timezone and the wp-settings file set to UTC, can I suspect all those initially migrated records need to be updated?

    Also, when using a timezone different in the Settings GUI and I query or insert into the mysql database directly, I must adjust for UTC? All this came to question when I created a plugin that inserted records into a custom table using the PHP date function and those dates posting as UTC.

    Thanks again for your help!

    I think you’re on the right track, but just to review:

    1. Do NOT modify the core code of WordPress.
    2. Modify Settings -> General -> Timezone to your local timezone.
    3. Your developers will need to manually update all rows in wp_posts by changing post_date to the timezone adjusted date based on post_date_gmt
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Timezone’ is closed to new replies.