Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts

    how to add 1 year onto date

    Hello everyone

    I get a date from a var and I have this to change it into unix date farmat



    PHP Code:
    '".intval(strtotime($date))."' 
    which is great BUT now I need to add 1 year onto that date so I can set an expiry date and hopefully later I can check against it.

    How do I add 1 year onto the date? As in one year from now whenever now is.

    Does that make sense.

    thanks

    LT

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    http://php.net/manual/en/function.strtotime.php
    echo strtotime("+1 day"), "\n";
    "Yeah science!"
    Online Science Tools

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Hi djh101

    thanks but i'm not clear

    this will go to database

    PHP Code:
    '".intval(strtotime($date))."' 
    but I need to add on 1 year

    are you saying I can do this

    '".intval(strtotime($date "+365 days"))."'

    ???

    LT

  • #4
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    That depends what you are setting $date as- it has to have a value. I've never used strtotime before, so I'm just going by what I'm reading (feel free to read the link, or read the page on w3schools about strotime), but it seems like all it does is parse a date to unix format? If for $date your are using mktime or date, you can do date("y")+1 or $date = mktime(0, 0, 0, date("m"), date("d"), date("y")+1);
    "Yeah science!"
    Online Science Tools

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Thanks djh101

    I read / am reading the link

    anyway
    expected date format put into $date
    00:31:02 Nov 03 2010 PDT

    this '".intval(strtotime($date))."' will convert it to unix 1289049745 format

    but I need to add 1 year onto that before I send to DB because I want to set an expiry date that I can check against.

    thanks for trying tho, appreciate it.

    if anybody can explain how I achieve this that would be great

    LT

  • #6
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    Actually, with a little reading about UNIX time format and a little testing, '".intval(strtotime($date."+1 year"))."' will return whatever you have in $date plus 1 year (31536000 seconds). If you want to add the expiration manually when you get the string, though, date("y")+1 will still work.
    Last edited by djh101; 12-01-2010 at 11:37 AM.
    "Yeah science!"
    Online Science Tools

  • Users who have thanked djh101 for this post:

    low tech (12-01-2010)

  • #7
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Hi

    yeh that looks like it will do the trick --- excellent effort

    I was reading this page that I found

    http://php.bigresource.com/Track/php-trF74y5i/

    anyway

    thanks very much --- :-)

    LT


  •  

    Posting Permissions

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