tech1984
asked on
PHP strtotime unexpected result
The below code echos out 20101111 instead of my expected result of 20101105.
I am running PHP 4.3.2.
Any Ideas why it is doing this?
I am running PHP 4.3.2.
Any Ideas why it is doing this?
<?
$date = date('Ymd',strtotime('+1 months',strtotime('20101001')));
echo date('Ymd',strtotime('next friday',strtotime($date)));
?>
that code is working fine for me using : 5.3.2.
on later php version it gives ok time..
you can try wit singular "month"
you can try wit singular "month"
<?php
$date = date('Ymd',strtotime('+1 month',strtotime('20101001')));
echo date('Ymd',strtotime('next friday',strtotime($date)));
?>
ASKER
ovi_mihai - Changeing month the months did not work, the problem seems to be how strtotime handles next in php previous to version 4.4.
From PHP.net:
In PHP versions prior to 4.4.0, "next" is incorrectly computed as +2. A typical solution to this is to use "+1".
I need a work around for this know bug, besides upgrading php.
From PHP.net:
In PHP versions prior to 4.4.0, "next" is incorrectly computed as +2. A typical solution to this is to use "+1".
I need a work around for this know bug, besides upgrading php.
well, my understanding is previous works ok
so you could try the following
so you could try the following
<?php
$date = date('Ymd',strtotime('+1 month',strtotime('20101001')));
echo date('Ymd',strtotime('previous friday',strtotime('next friday',strtotime($date))));
?>
ASKER
jrm213jrm213 -
your code returns 19691231
your code returns 19691231
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what do u need to do exactly?
sorry not sure why it posted that codeblock with the message.
this code does the same , but im not sure if thats what u want
<?
$date = date('Ymd',strtotime('+1 months',strtotime('20101001')));
echo date('Ymd',strtotime('+1 friday',strtotime($date)));
?>
i ment it gives u "20101105" . try it on php 4
ASKER
Changing previous to last fixed the issue. Thanks for the solution.