Page 1 of 1
[RESOLVED] How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 12:38 pm
by simonmlewis
Hi
PHP's well used:
Is useful to find the date in the system.
However, what do I do to gather the date in a fortnight's time??
Simon
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 12:56 pm
by mischievous
Option #1:
Code: Select all
$today = time();//Unix Time Stamp
$amount_of_days = 14; //Number of days to add
$futuretime = 60 * 60 * 24 * $amount_of_days; //60 seconds times 60 minutes times 24 hours times the number of days ahead
$futuredate = date('Y-m-d', $futuretime) //put in date format
Option #2:
Code: Select all
$futuredate = strtotime("+14 day");
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 1:22 pm
by simonmlewis
Thx.
The first option gives the result:
1970-01-15
The second gives:
1249496533
Something not quite right?
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 2:22 pm
by simonmlewis
Unless anyone has a better method, think I just found the way - after about an hour of searching:
Code: Select all
<?php
$fortnight = date("Y-m-d", (time() + (86400*14)));
echo $fortnight;
?>
Some mktime methods just produce a load of numbers for some reason. And then you have to stick a function above them.
This method is short and easy.
Simon
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 2:32 pm
by simonmlewis
Damn it - just realised I don't a fortnight ahead of today, but a fortnight ahead of a given day.
It's the Pseucode:
Code: Select all
variable = subscription date + 14 days.
if the result of (variable) <= todayDate, then do something.
Can anyone help please, bearing in mind I have the code below?
Code: Select all
$fortnight = date("Y-m-d", (time() + (86400*14)));
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 2:39 pm
by spider.nick
simonmlewis wrote:Damn it - just realised I don't a fortnight ahead of today, but a fortnight ahead of a given day.
It's the Pseucode:
Code: Select all
variable = subscription date + 14 days.
if the result of (variable) <= todayDate, then do something.
Can anyone help please, bearing in mind I have the code below?
Code: Select all
$fortnight = date("Y-m-d", (time() + (86400*14)));
The following should work:
Code: Select all
$subDateMicrotime = strtotime('subscription date');
$fortnight = date( "Y-m-d", ($subDateMicrotime + (86400*14)) );
Post back to let me know how it works.
Nick
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 3:01 pm
by simonmlewis
That works - however I now now have stage two to complete.
I need to do an if statement that asks if the $subscriptiondate <= $fortnight.
They get the system for free for a fortnight, so I need to see if they have used it for a fortnight. If they haven't yet, just pass them through, if they have gone over that, then send them somewhere else.
I can do the latter part easy - it's just the IF I need to sort.
I have tried this:
Code: Select all
$timeStamp = strtotime("$row->subscribed");
$timeStamp += 24 * 60 * 60 * 14;
$fortnight = date("Y-m-d", $timeStamp);
if ($timestamp <= $fortnight) {......................
But for the date I have for this person, and the date on my system, it should reject the person, but it isn't. The date on the system is mid Sept, and the date for the person is 2009-09-02. Basically, it's more than a fortnight.
Re: How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 3:08 pm
by spider.nick
simonmlewis wrote:That works - however I now now have stage two to complete.
Good!
Now, go back to your first post, and click the 'Edit' button. Change the post title from
How do you add 14 days to a $today script? to
[RESOLVED] How do you add 14 days to a $today script?.
Once you do that, make sure to start a new post with your new question.
Nick
Re: [RESOLVED] How do you add 14 days to a $today script?
Posted: Wed Jul 22, 2009 3:30 pm
by Weirdan
If you need fortnight you may ask for just that:
Code: Select all
var_dump(date("Y-m-d", strtotime("next fortnight", strtotime("2008-02-10"))));