www.webdeveloper.com
Results 1 to 5 of 5

Thread: Figuring date 1 year from variable

  1. #1
    Join Date
    Sep 2008
    Posts
    32

    Figuring date 1 year from variable

    I am trying to figure and expiration date one year from the create date. This should be such a simple thing, however, its not working for me!

    $temp['createDate'] retrieves 2008-11-07 12:37:40 in mySql database.


    $expireDate = strtotime("$temp['createDate'] + 1 year");
    echo $expireDate;

    What is returned is 1257615460 .

    How can I make the date returned be 2009-11-07, which is one year after the variable date minus the time?

  2. #2
    Join Date
    Aug 2007
    Location
    Washington
    Posts
    219
    Thats because strtotime returns a Unix timestamp. http://us3.php.net/strtotime

    What you want is something like this:
    PHP Code:
    $expireDate strtotime("$temp['createDate'] + 1 year");
    $newDate date("Y-m-d g:i:s"$expireDate);
    echo 
    $newDate

  3. #3
    Join Date
    Sep 2008
    Posts
    32
    Thank you.... I almost had it! I just needed to format the date.

    Also, just one more thing so I understand this completely....

    The 1257615460 that was returned by the echo is the number of seconds since January 1 1970 00:00:00 GMT? Is that correct?

  4. #4
    Join Date
    Nov 2008
    Posts
    2,477
    Correct

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    Note that this could instead be done as part of the query, if you wanted:
    Code:
    SELECT col1, col2, col3, DATE_ADD(date_column, INTERVAL 1 YEAR) AS expire_date FROM . . .
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles