From:             alessio at alias2k dot com
Operating system: Debian 6
PHP version:      Irrelevant
Package:          *General Issues
Bug Type:         Bug
Bug description:Date object

Description:
------------
---
>From manual page: http://www.php.net/datetime.sub#refsect1-datetime.sub-
description
---

When you have a datetime object you can modify the date adding or
subtracting 
month. If you do that, the result is always unpredictable, because the
mktime, 
the sub, or the modify function, always subtract the amount of days of the

previous month. I'll make an example:
If I do
<?php
$date = new DateTime('2001-03-31');
$interval = new DateInterval('P1M');

$date->sub($interval);
echo $date->format('Y-m-d');
?>
I obtain 2001-03-03 as result, but I've expected to have 2001-02-28,
because the 
previous month is february, not 28 days first.
We have the same problem if we add some months to our starting date:

<?php
$date = new DateTime('2001-03-31');
$interval = new DateInterval('P1M');

$date->add($interval);
echo $date->format('Y-m-d');
?>
I obtain 2001-05-01 as result, but also in this case I've aspected a
different 
result, i think the right value is 2001-04-30, because you have to add the
days 
of the next month to obtain the right result, not the days of current
month.
.
The problem is also the communication with mySql, because mySql calculate
the 
right result, so the comparison between two date it's impossible

Test script:
---------------
<?php
$date = new DateTime('2001-03-31');
$interval = new DateInterval('P1M');

$date->sub($interval);
echo $date->format('Y-m-d');
?>

Expected result:
----------------
2001-02-28

Actual result:
--------------
2001-03-03

-- 
Edit bug report at https://bugs.php.net/bug.php?id=64347&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64347&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64347&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64347&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64347&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64347&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64347&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64347&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64347&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64347&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64347&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64347&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64347&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64347&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64347&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64347&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64347&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64347&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64347&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64347&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64347&r=mysqlcfg

Reply via email to