Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2010, 10:09 AM   PM User | #1
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
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
low tech is offline   Reply With Quote
Old 12-01-2010, 10:16 AM   PM User | #2
djh101
Regular Coder

 
djh101's Avatar
 
Join Date: May 2009
Location: Santa Clarita
Posts: 607
Thanks: 48
Thanked 63 Times in 63 Posts
djh101 is an unknown quantity at this point
http://php.net/manual/en/function.strtotime.php
Quote:
echo strtotime("+1 day"), "\n";
__________________
"Yeah science!"
Online Science Tools
djh101 is offline   Reply With Quote
Old 12-01-2010, 10:32 AM   PM User | #3
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
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
low tech is offline   Reply With Quote
Old 12-01-2010, 10:35 AM   PM User | #4
djh101
Regular Coder

 
djh101's Avatar
 
Join Date: May 2009
Location: Santa Clarita
Posts: 607
Thanks: 48
Thanked 63 Times in 63 Posts
djh101 is an unknown quantity at this point
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
djh101 is offline   Reply With Quote
Old 12-01-2010, 10:52 AM   PM User | #5
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
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
low tech is offline   Reply With Quote
Old 12-01-2010, 11:34 AM   PM User | #6
djh101
Regular Coder

 
djh101's Avatar
 
Join Date: May 2009
Location: Santa Clarita
Posts: 607
Thanks: 48
Thanked 63 Times in 63 Posts
djh101 is an unknown quantity at this point
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.
__________________
"Yeah science!"
Online Science Tools

Last edited by djh101; 12-01-2010 at 11:37 AM..
djh101 is offline   Reply With Quote
Users who have thanked djh101 for this post:
low tech (12-01-2010)
Old 12-01-2010, 12:09 PM   PM User | #7
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
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
low tech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.