• Resolved AbacusDataSystems

    (@abacusdatasystems)


    The date at the right side of the header at https://www.mornystannit.info has never been wrong until now. I noticed it just a few days ago, but do not know exactly when the date display went wrong. Now, it always shows the time as “14:33”, and the year is random; only the day of the month is correct.

    What on Earth could have caused this suddenly?

    The code has never been changed. Here it is:

    $d = ‘Y-m-j H:i:s’;
    $datum = mysql2date( ‘H:i, l, jS F, Y’, time($d) );
    $before = ”;
    $after = ”;
    echo apply_filters(‘the_date’, $datum, ‘H:i, l, jS F, Y’, $before, $after);

Viewing 5 replies - 1 through 5 (of 5 total)
  • I am not sure if you copied the wrong code, but the PHP function “time” [1] does not accepts any parameter, so that variable “$d” is irrelevant here, what you are currently doing there is passing the current timestamp to the “mysql2date” function [2] which changes every second.

    Edit. By the way, the WordPress function “mysql2date” automatically converts the date to time format so you have to remove that “time” from there. Anyway, I think that may be the root of the issue, but also that you are using a filter (which currently is undocumented) instead of a normal function like “the_date” [3].

    [1] https://php.net/manual/en/function.time.php
    [2] https://codex.www.ads-software.com/Function_Reference/mysql2date
    [3] https://codex.www.ads-software.com/Function_Reference/the_date

    Thread Starter AbacusDataSystems

    (@abacusdatasystems)

    You’re right about the ‘time()’ function, Yorman. Thanks. This code was already part of the WP theme. The mystery is that it has worked correctly for years, and only now has malfunctioned.

    Thanks for your help and the references. I can fix the problem now.

    Thread Starter AbacusDataSystems

    (@abacusdatasystems)

    I found the problem. I had changed date($d) to time($d) because date($d) does not account for daylight saving time.

    I have just changed it back to date($d). Now, unfortunately, the problem of the daylight saving time is back again. The site now shows the time to be an hour earlier than it actually is.

    Here [1] is a good explanation of how to deal with the daylight difference, or you can also add the “capital i” flag [2] in the “date” function to force PHP to return the time correctly.

    You can also do something like this [3] where you can use the timezone configured by you in the general settings page. I had to modify the code shown in this commit to display the time of the logs processed by a plugin that I maintain according to the timezone defined by the users.

    [1] https://stackoverflow.com/a/19756063
    [2] https://php.net/manual/en/function.date.php
    [3] https://plugins.trac.www.ads-software.com/changeset/1172856

    Thread Starter AbacusDataSystems

    (@abacusdatasystems)

    Thanks to your well-ordered and well-presented replies, the problem is now solved. Thank you, Yorman.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Current date display has gone crazy!’ is closed to new replies.