WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Time (and dates) incorrect on site (8 posts)

  1. mark
    Member
    Posted 1 year ago #

    I have some strange issues with time and date on my WordPress site. I'll start off by saying by General Settings is set to the correct timezone and displays properly on the the settings page to the current date and time.

    I have posted a PHP script on a WordPress page. All works properly except the date and time. The script is for a team schedule and standings and shows the proper time on its own, see: http://www.nmclippers.com/standings.php?conf=1 . If you look at the dates and times of games on bottom of page they are correct.

    When placed on my WordPress page though, the date is off by a day and the time by an hour. See here: http://www.nmclippers.com/standingspage/?conf=1

    I understand this is not totally a WordPress related problem but I was not sure of where else to post. If someone could point me in the right direction, I would appreciate it.

    Also, to get the script to work I added the PHP code to a template and it works. Not sure if that is the proper way to do this, but it does work (besides the time issue).

    Thanks for any help or advice.

  2. MarkRH
    Member
    Posted 1 year ago #

    I'm sure it has something to do with differences in timezones. I'd first add some timezone reference to the dates being displayed.

    define("DATE_FORMAT","[d-M-Y h:i:s A T O]");  // [10-Oct-2012 05:46:34 AM CDT -0500]
    $now = date(DATE_FORMAT);
    echo '<p>The date/time on the server is: '.$now.'</p>';

    In the above example, "T" is the timezone and "O" is the offset from GMT. I you add this to the scripts on both pages it will at least let you know if the base timezone settings within each script is different or not.

    I am guessing these dates and times are stored in a database? What is the actual data within the database and how does that compare with what's being shown on the site(s)?

    The site with the correct time, is it modifying the date within the script before displaying it? If so, on the other site it might be incorrectly modifying it if the base timezones for the scripts are not the same and you simply copy/pasted the code.

    Hopefully this makes sense LOL.

  3. mark
    Member
    Posted 1 year ago #

    Wow, that is a mouthful, LOL.

    I entered the given code. On the standalone page, the response is:

    The date/time on the server is: [03-Nov-2012 09:28:02 PM MDT -0600]

    On the WP page, the response is:

    The date/time on the server is: [03-Nov-2012 08:28:00 PM PDT -0700]

    So that explains the times being off by an hour. I am assuming make an adjustment to the General Settings on WP site is easiest way to adjust?

    And is does not address the issue of the days being off. It is the exact same script copy and paste into WP using the plugin 'Code Insert Manager'.

    Thank for taking a look, I know not the simplest of problems, any other input would be great.

  4. MarkRH
    Member
    Posted 1 year ago #

    Keep the Timezone setting in your blog's General Settings set such that the Local Time on the right matches the time shown on your watch. That way, your post times will look correct to you. That's how I'd set WordPress itself.

    I looked on your sites and now standalone has:
    November 03, 2012 8:00am Starrz (Cochiti)
    The date/time on the server is: [03-Nov-2012 10:18:28 PM MDT -0600]

    And the other on WP:
    November 03, 2012 3:00pm Starrz (Cochiti)
    The date/time on the server is: [04-Nov-2012 05:18:35 AM CET +0100]

    That's a 7 hour difference which matches the difference between the game times. With a 7 hour difference, the day would also be different depending when you looked at it.

    You will probably have to modify the code in one script or the other to change how it manipulates the date before displaying it on the page. Or you might try this. On the standalone page add:

    $timezone = date_default_timezone_get();
    echo 'timezone string on server is: '.$timezone.'<br>';

    Make a note of that output. Then in the WordPress script at the beginning of it, try:

    $standalone_timezone = '(*** whatever the other script said ***)';
    $wp_timezone = date_default_timezone_get();
    echo 'wp timezone string on server is: '.$wp_timezone.'<br>';
    date_default_timezone_set($standalone_timezone);

    Make sure you change (*** whatever the other script said ***) above to match. Then, at the end of the WordPress script, add the following to set the timezone back:

    date_default_timezone_set($wp_timezone);

    Hopefully, that will get it to display the dates with the same values.

  5. mark
    Member
    Posted 1 year ago #

    Adding the script

    $standalone_timezone = '(*** whatever the other script said ***)';
    $wp_timezone = date_default_timezone_get();
    echo 'wp timezone string on server is: '.$wp_timezone.'
    ';
    date_default_timezone_set($standalone_timezone);
    does not seem to have an effect. Sounded good in theory. I tried adding in different portions of the script and no luck.

    I added that output to both pages, WP page has

    The date/time on the server is: [03-Nov-2012 11:22:46 PM PDT -0700]
    timezone string on server is: America/Los_Angeles

    while standalone has

    The date/time on the server is: [04-Nov-2012 12:18:55 AM MDT -0600]

    timezone string on server is: America/Denver

    I began looking at my plugins. I deactivated All-in-One Event Calendar and Game Schedule plugin. Both change the output of the time zone on the WP page. Seems to be the source of the problems between these two plugins (both which I would like to keep for functionality).

    It always comes down to another plugin, right? LOL

    Can I add anything to those plugins to reset to WP timezone? I'm super frustrated now.

  6. mark
    Member
    Posted 1 year ago #

    However, when I deactivate all plugins the time zone output is now:

    The date/time on the server is: [04-Nov-2012 06:36:34 AM UTC +0000]
    timezone string on server is: UTC

  7. mark
    Member
    Posted 1 year ago #

    Finally, I fixed it (with your help)

    Used this code to set timezone in the script added to WP page:

    <?php
    date_default_timezone_set('America/Denver');

    $script_tz = date_default_timezone_get();

    if (strcmp($script_tz, ini_get('date.timezone'))){
    echo 'Script timezone differs from ini-set timezone.';
    } else {
    echo 'Script timezone and ini-set timezone match.';
    }
    ?>

    Would not have figured it out without your help. Many thanks.

  8. MarkRH
    Member
    Posted 1 year ago #

    Cool. Yeah, the timezone stuff can get nutty sometimes. Glad you got it figured out.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.