/    Sign up×
Community /Pin to ProfileBookmark

strtotime calculation not adding up

Hi – This function was supposed to calculate the next delivery date based on a start date and by adding 2, 4, 6 or 8 week intervals until past “today”. I’ve done something wrong because it seems to just be adding intervals from “today”.

[code=php]function next_shipment($start_date, $freq) {

//for $start_date use date format 2012/12/30 = year/day/month
$start = strtotime(“$start_date”);
while ( $start <= strtotime(‘today’)) { $start = strtotime(“$start + $freq weeks”); }
$next_delivery=$start;
echo date(‘l F j, Y’, $next_delivery);

}[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@robahasauthorFeb 26.2012 — For anyone one interested, here's how I got it to work (since time stamp in seconds, I converted all the variables into seconds and that removed any problems)

function next_shipment($start_date, $freq) {

$freq = $freq * 604800; //this is the number of seconds in a week

$start = strtotime("$start_date");

$today = strtotime('today');

while ( $start <= $today ) { $start = $start + $freq; }

$next_delivery=$start;

echo date('l F j, Y', $next_delivery);

}
Copy linkTweet thisAlerts:
@ssystemsFeb 26.2012 — [code=php]
$next_delivery = date('l F j, Y', strtotime('+' . $freq . ' week', $start_date));
[/code]
Copy linkTweet thisAlerts:
@CharlesFeb 26.2012 — For anyone one interested, here's how I got it to work (since time stamp in seconds, I converted all the variables into seconds and that removed any problems)[/QUOTE]Just be warned, it's not going to work so well around the daylight savings time changes. That may not be something to worry about here but sometimes it will trip you up.
×

Success!

Help @robahas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...