How can I set php dates 10 years into the future?

Discussion in 'PHP' started by liquid2g, Feb 14, 2011.

  1. #1
    Hi everyone,

    I'm writing a science fiction wordpress blog set 10 years into the future.
    I basically need all posts to display as if they are 10 years from now.

    Eg. posts needs to display as:
    February 7, 2021 instead of
    February 7, 2011

    This will be for every post that I write.


    How can I automatically add 10 years to every post date?
    (And where would I put that code?)

    Currently, the wordpress php is calling the date with `<?php the_time(__('M j, Y')) ?>`

    I realise it's a bit of an odd request, but it's necessary for this particular project. I know it's possible - but I'm brand new to php and am not sure how. =)

    I hope someone out there can help. It would be very much appreciated.

    many thanks in advance

    Luke
     
    liquid2g, Feb 14, 2011 IP
  2. Simple Link Media

    Simple Link Media Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $future_time = the_time(__('M j, ')) . (the_time(__('Y')) + 10);
    PHP:
    Not sure whether it works or not ( no access to a server at the moment ) but it should - let us know if you have any issues with implementing this.
     
    Simple Link Media, Feb 15, 2011 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Hi,

    the_time() function echoes the time out, so isnt suitable for what you want to do.

    You have 2 options; use a custom select and just add an interval of 10 years to the post_date, or perhaps easier you can use get_the_date inside the loop and it will give you the current posts date.

    Outsode of the loop, you will have to pass in the post id or post object.

    <?php
    $date = get_the_date();
    $daymonth = date("M j", strtotime($date)); # the day and the month
    $year = date("Y", strtotime($date)) + 10; # the year
    print "$daymonth $year";
    ?>
    PHP:
    This is suitable, as mentioned above, for sections of the site inside the loop. Should be fine to include this in theme files such as single.php etc
     
    lukeg32, Feb 15, 2011 IP
  4. Thibaut

    Thibaut Well-Known Member

    Messages:
    886
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Use mktime() and simply add the expected time:

    $a = mktime() + 60 * 60 * 24 * 365 * 10 // Add 10 years

    Cheers.
     
    Thibaut, Feb 15, 2011 IP
  5. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Or you could read his question again and its how about how to get a wordpress date to the desired value?

    *sigh*
     
    lukeg32, Feb 15, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    why are you doing it so hard?

    $futuretime = time() + (60*60*24*365*10);

    DOne!
     
    G3n3s!s, Feb 15, 2011 IP
  7. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #7
    NO! no its not.... its pulling a WP post and adding 10 years onto the POST DATE!

    READ the OP FFS!!
     
    lukeg32, Feb 15, 2011 IP
  8. liquid2g

    liquid2g Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8

    Thanks G3n3s!s, this looks good. I'm just not sure where to put the function you suggest in my wordpress files... any ideas to try would be very much appreciated.
     
    liquid2g, Feb 15, 2011 IP
  9. liquid2g

    liquid2g Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks lukeg32, this looks like it will work, but I'm not sure where this code should go.
    Sorry, I'm new to php -this is the first time I've needed to really get into it. =)
    I'd be very appreciative though if you could let me know.
     
    liquid2g, Feb 15, 2011 IP
  10. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #10
    okay, sorry so this one


    $date = get_the_date();
    $futuretime = $date + (60*60*24*365*10);
     
    G3n3s!s, Feb 16, 2011 IP
  11. seoelk.com

    seoelk.com Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    not all years are 365 days long ...
     
    seoelk.com, Feb 16, 2011 IP
  12. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #12
    does it matter? Just few-days more
     
    G3n3s!s, Feb 16, 2011 IP
  13. seoelk.com

    seoelk.com Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    well it doesn't meet topic author's example

     
    seoelk.com, Feb 16, 2011 IP
  14. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #14
    okay, so sorry..

    $date = get_the_date();
    $futuretime = strtotime($date) + mktime(0,0,0,0,0,10);
    $date = date("d.m.Y", $futuretime);
     
    G3n3s!s, Feb 16, 2011 IP
  15. liquid2g

    liquid2g Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Aha! Thanks Luke32!

    It works brilliantly with...
    <?php
    $date = get_the_date();
    $daymonth = date("M j", strtotime($date)); # the day and the month
    $year = date("Y", strtotime($date)) + 10; # the year
    print "$daymonth $year";
    ?
    PHP:
    I've implemented it across almost all dates on my wordpress site, but can't work out how to change the date in the 'Archives' widget sidebar. I tried archives.php but couldn't find what I needed to change... Does anyone know?

    thanks again!
     
    liquid2g, Feb 17, 2011 IP