[resolved] Pre 1970 dates (9 posts)

  1. greencode
    Posted 4 years ago #

    I've been trying to add content that needs to be dated pre-1970 but have noticed it doesn't seem to stick to that date and instead displays today's date. I've had a hunt around and it does seem this is an ongoing issue. Does anyone know of any way to resolve it other than me having to create a custom field to add the date?

  2. flamenco
    Posted 4 years ago #

    It sounds very much like you've run into a Unix system limitation. The operating system "starts" on the last day of 1969.


    So if you're using a Unix date function, then that would explain it, and you'll likely need to make something custom for that.


  3. greencode
    Posted 4 years ago #

    Now then I've looked around and found this post http://wordpress.org/support/topic/pre-1970-dates-no-longer-handled-correctly?replies=12 which says to comment out this code in the wp-includes/functions.php file:

    if ( false === $i || intval($i) < 0 ) {
    		if ( ! $gmt )
    			$i = current_time( 'timestamp' );
    			$i = time();
    		// we should not let date() interfere with our
    		// specially computed timestamp
    		$gmt = true;

    which works perfectly and now dates are displaying as far back as I need i.e. 1932 but a couple of things:

    1. Is it okay to do this i.e. will it affects anything else and…
    2. Is there are a better way of doing this so when I update WordPress I don't have to update that file each time?

  4. greencode
    Posted 4 years ago #

    Well, I've gone ahead and done the above and all's working well. Just need to remember to comment out the code on each new WordPress release!

  5. esmi
    Forum Moderator
    Posted 4 years ago #

    Don't edit core code! Apart from the risk of breaking your entire site, you may create security loopholes in your WordPress install.

    Is there are a better way of doing this

    Yes. Use custom fields for pre-1970 dates in the format yyyy-mm-dd.

  6. greencode
    Posted 4 years ago #

    Hi. Thanks for this - can you explain what code I would enter and how I would display it in my template. Thanks.

  7. esmi
    Forum Moderator
    Posted 4 years ago #

    See Using_Custom_Fields. You can suppress the real post date in your theme's template files and even display posts in pre-1970 "date" order by using a custom query.

  8. greencode
    Posted 4 years ago #

    I ended up using this:

    <?php if( $image = get_post_meta($post->ID, "year", true) ): ?>
    <?php echo $image; ?>
    <?php else: ?>
    <?php the_time('Y') ?>
    <?php endif; ?>
  9. oqm4
    Posted 4 years ago #

    My company's outlined a temporary workaround here, and a full-fledged WordPress plugin is in the works. We'll release it in the next few weeks.

    Keep an eye on the SH site, our Google Code project site, and the SH WordPress plugins pages:

    - http://studiohyperset.com/projects/wordpress-plugins
    - http://profiles.wordpress.org/users/studiohyperset/

    ... for more details.

Topic Closed

This topic has been closed to new replies.

About this Topic