SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I add one year to the current date

    I will use the date function to get the current date but then I want to add one year to the date. So I am left with what the date would be in a years time. How would I do this?

    Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,049
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    adding a year

    Have you tried
    PHP Code:
    $nextYear = (date("Y")+1); 

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague
    Have you tried
    PHP Code:
    $nextYear = (date("Y")+1); 
    I don't think that works. It outputs "1" for me...

    This should work, though:

    PHP Code:
    echo strtotime("+1 year"); 
    The Banana Stand - an Arrested Development fansite
    LC-3 Help - tutorials on the LC-3 educational assembly language

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,049
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    Next year

    Quote Originally Posted by thirteenlisk
    I don't think that works. It outputs "1" for me...
    HUH? check again, for me it evaluates to 2006
    Quote Originally Posted by thirteenlisk
    echo strtotime("+1 year");
    outputs:
    1154411021
    as per the php docs:
    "strtotime -- Parse about any English textual datetime description into a UNIX timestamp"
    So, aaron118, there you go, now you have at least 2 ways to get what you need.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague
    HUH? check again, for me it evaluates to 2006
    Sorry, you're absolutely right. Your method works great.
    The Banana Stand - an Arrested Development fansite
    LC-3 Help - tutorials on the LC-3 educational assembly language

  6. #6
    SitePoint Addict
    Join Date
    May 2005
    Posts
    297
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would the code be so it gave me the day and month in a years time as well?

    Thanks

  7. #7
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $nextYear = (date("Y")+1);
    echo (date("D, M,".$nextYear.""));



    That would output:
    Mon, Aug, 2006
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  8. #8
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My last post is kinda goofy... copying/posting with advanced setting is odd...

    anyway:

    if you want something like: 8/1/2006 you could do:

    $nextYear = (date("Y")+1);
    echo (date("m/d/".$nextYear.""));

    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •