WordPress.org

Ready to get started?Download WordPress

Forums

Post Timestamp Limit (10 posts)

  1. pwkingston
    Member
    Posted 6 years ago #

    I am using my wordpress install to share newsletters and other family writing from the past century, and maybe even older. I have been setting the post timestamp for the dates of these letters and events, but so far I am seemingly unable to set a date earlier than 1969-12-31, 6:00:00 pm. If I set a date earlier than that, the date is automatically set for this date. Is this a function of my sql server or a limitation in/of wordpress?

    My archive list displays the entrys correctly, as if they have the correct time stamp, but the edit post page shows the date as 1969-12-31, 6:00:00 pm.

    Individual entry - http://www.thedelawaresofidaho.org/wordpress/?p=236

    Archive link -
    http://www.thedelawaresofidaho.org/wordpress/?m=191912

    Thanks for looking at this!

    ~Pete

  2. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    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.

  3. pwkingston
    Member
    Posted 6 years ago #

    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.

  4. whooami
    Member
    Posted 6 years ago #

    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 :)

  5. pwkingston
    Member
    Posted 6 years ago #

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

  6. whooami
    Member
    Posted 6 years ago #

    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.

  7. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    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'];
    }?>

  8. pwkingston
    Member
    Posted 5 years ago #

    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

    ?

  9. pwkingston
    Member
    Posted 5 years ago #

    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.

  10. Terragg
    Member
    Posted 5 years ago #

    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. :)

Topic Closed

This topic has been closed to new replies.

About this Topic