php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54000 date_create bug
Submitted: 2011-02-12 15:46 UTC Modified: 2011-02-15 22:31 UTC
From: phunsanit at hotmail dot com Assigned:
Status: Not a bug Package: Windows Installer
PHP Version: 5.3.5 OS: windows 7 / linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phunsanit at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-02-12 15:46 UTC] phunsanit at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.construct#Errors/Exceptions
---
i create date  2011-02-31
it impossible
but menthod date_create
don't error 
it return 2011-02-31

Test script:
---------------
$date = date_create('2011-02-31');
if (!$date)
{
    $e = date_get_last_errors();
    foreach ($e['errors'] as $error) {
        echo "$error\n";
    }
}
else
{
	echo date_format($date, 'Y-m-d');
}
return 2011-03-03

Expected result:
----------------
 2011-03-03

Actual result:
--------------
return false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-15 22:31 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-02-15 22:31 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is correct. PHP automatically adjust for value underflows and overflows. Since more recent PHP versions, it will add a warning for invalid dates though:

<?php
$date = date_create('2011-02-31');
var_dump(date_get_last_errors());
?>

array(4) {
  ["warning_count"]=>
  int(1)
  ["warnings"]=>
  array(1) {
    [11]=>
    string(27) "The parsed date was invalid"
  }
  ["error_count"]=>
  int(0)
  ["errors"]=>
  array(0) {
  }
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 22:01:29 2024 UTC