• Resolved FRANTIC

    (@frantic)


    Hello, everyone!
    This is my first post in the WP support forum.
    I hope I’m doing this right. 🙂

    Just a little info about my blog…
    UTC offset = -5
    On the front page (index.php) I display posts from the current day only (see CODE 1).

    So, here’s my problem…

    I want to have a certain post display at 12:01 (midnight) of the next day (so if today is the Saturday, I want my post to show up on Sunday at 12:01am).

    So, I set the day and date and post timestamp for 00:01, and check the “Edit timestamp.” I wait for my post to appear at 12:01 am, and nothing. The post shows up at 2:01 am, 2 hours late.

    And another thing.

    I have today’s date displaying on my site, with the code (see CODE 2) in my header.php file. For some odd reason, the time is 2 hours behind the time that appears on the Options page (Default time format Output). So, my posts from the current day always get cleared at 2:00 am, not at 12:00 am as they should.

    Does anyone heave any idea why all of this is happening? And perhaps how to fix the problem?

    Thank you.

    CODE 1——————————-
    This code is placed just before THE LOOP (if (have_posts()) : …) starts:

    $current_day = date(‘d’);
    $current_month = date(‘m’);
    $current_year = date(‘Y’);

    query_posts(“cat=-63&year=$current_year&monthnum=$current_month&day=$current_day”);
    ——————————-

    CODE 2——————————-
    $current_dayName3 = date(‘l’);
    $current_monthName3 = date(‘F’);
    $current_dayNO3 = date(‘d’);
    $current_year3 = date(‘Y’);

    $current_hour2 = date(‘h’);
    $current_min2 = date(‘i’);

    echo($current_dayName3 . ‘, ‘ . $current_monthName3 . ‘ ‘ . $current_dayNO3 . ‘, ‘ . $current_year3);
    ——————————-

Viewing 4 replies - 1 through 4 (of 4 total)
  • The date() function will return the time and date on the server, which is not necessarily the same as the time set for WordPress.

    If your server is in a timezone two hours behind you, then this is pretty much what I’d expect to see.

    I’m not much of a coder, but I think the PHP functions date and mktime should let you adjust for the difference.

    Thread Starter FRANTIC

    (@frantic)

    Thanks for the suggestion, LesBessant.

    I’ll give it a try.

    Thread Starter FRANTIC

    (@frantic)

    Ok, so this is what I ended up doing.

    I used the PHP function date_default_timezone_set() to set my actual timezone: date_default_timezone_set(‘America/Toronto’).

    Now, the output of CODE 1 (from my initial post), outputs the correct date, where before it was 2 hours behind.

    I’m still not sure if this will fix all the problems; I’ll have to wait ’till 12:01 am to find out how the future posts behave.

    Thread Starter FRANTIC

    (@frantic)

    Sweet.

    Looks like everthying (see my previous post) is working fine now.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Future posts display 2 hours late’ is closed to new replies.