Support » Fixing WordPress » Post Timestamp Limit

Viewing 9 replies - 1 through 9 (of 9 total)
  • Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    This is a function of wordpress, not your server.
    For programmatically logical functionality, most software that needs to be able to perform calculations on dates/times use a starting point. All dates are calculated from then. For instance, it is common to use a 99 year clock, and calculate every date as an amount of time since then, assuming that in 99 years your operating system or software won’t be used anymore.

    Having said that, wordpress stores all dates in mysql just the way you see them, ie “1900-03-01 11:50:15”
    When it retrieves the date/time it breaks it up for manipulation purposes.

    If it’s showing the correct date for your archive listing, but not for your single post display, one solution would be to just do a direct sql query on that particular field in the single.php or whichever php file you’re on.

    I am going to have a lot of posts earlier than 1969. Is there a file that I can edit to change this starting date, make it do the “direct sql query”? It makes it difficult to manage the posts on the admin side, because they are all displaying the 1969 date.

    whooami

    (@whooami)

    Member

    dates in MySQL are based on/start with Unix Epoch: 00:00:00 UTC/January 1, 1970

    there have been more than a few threads that discuss having dates earlier than that.

    http://wordpress.org/search/1969?forums=1

    Good luck 🙂

    Thanks! I searched, but not for the right things I guess. It looks like I have some work ahead of me!

    whooami

    (@whooami)

    Member

    i was looking at fixing this by writing a plugin, and decided to see how 2-1/2 handles it first. As far as I can tell this is “fixed” in 2-1/2, as I have a post with my birthday as the timestamp and it is correctly displayed on the front page, the archives, and on the single post page.

    I was born in 1965

    edit: oh! and my archives actually shows posts in jan/1965

    thats pretty sweet.

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    This code will get the date of the post you’re currently in directly from mysql. Just copy/paste it into your single.php or whatever file has your post display. Make sure to alter the prefix to reflect your particular setup.

    <?php
    $pid = $post->ID;
    $sql = “SELECT post_date FROM wp_<strong>or whatever your mysql prefix is</strong>posts WHERE ID=’$pid'”;
    $result = mysql_query($sql);
    if ( ! $result ){ echo mysql_error(); }
    else{
    $result2 = mysql_fetch_array($result);
    echo $result2[‘post_date’];
    }?>

    pwkingston

    (@pwkingston)

    This code does the trick!!!

    Thanks hallsofmontezuma!!!

    I changed things in my theme from –

    <?php the_time('F jS, Y') ?>

    and

    <?php the_time('F, Y'); ?>

    to

    <?php
    $pid = $post->ID;
    $sql = "SELECT post_date FROM wp_posts WHERE ID='$pid'";
    $result = mysql_query($sql);
    if ( ! $result ){ echo mysql_error(); }
    else{
    $result2 = mysql_fetch_array($result);
    echo $result2['post_date'];
    }?>

    and the output is like this –

    2008-08-20 15:38:25

    Do you know how to limit the date output to just year, month, day? What code would truncate it to just

    2008-08-20

    ?

    pwkingston

    (@pwkingston)

    Also, any ideas editing the admin pages to display the correct dates?

    /wordpress/wp-admin/post.php?action=edit&post=[post_id]

    (in the Publish Status side bar under the “Published on” )

    in the first column “date” (all shown as 1969 (because I am in mountain time) 1970 in other areas)

    /wordpress/wp-admin/edit.php

    I am going to have to find out if I can volunteer to work on fixing this specific issue in the developer group. It seems like if we change the way WordPress queries the date like in your fix that we can get around the php limitations entirely.

    This has been bugging me lately, I wanted to post something in the far future, c. 2039, and ran into the same problem of WP not handling the dates correctly.

    But the issue isn’t just in the queries, it is systemic everywhere WP does any sort of formatting or manipulation of dates/times.

    I think the solution is going to take adding a library that handles a range of dates outside the unix epoch limit, then hunt down every single date/time manipulation in the entire WP codebase and update the code to use the new date/time functions.

    Update: Found a related ticket Historical Dates (Pre 1901) Unsupported in WordPress

    So says the man whose biggest contribution to date has been alphabatizing the list of Templates in the Theme Editor. 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Post Timestamp Limit’ is closed to new replies.