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?
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 ;
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?
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
Forum Rules
Bookmarks