php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71386 Date returns the wrong month
Submitted: 2016-01-16 00:51 UTC Modified: 2016-01-16 04:54 UTC
From: ualison dot aguiar at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.17 OS: Linux - Open Suse
Private report: No CVE-ID: None
 [2016-01-16 00:51 UTC] ualison dot aguiar at gmail dot com
Description:
------------

When you run the script method format returns different date than was reported in the __construct

Test script:
---------------
1º Case
<?php
date_default_timezone_set('America/Sao_Paulo');
$date = new \DateTime('01/02/2016');
var_dump($date->format('d/m/Y'));
?>

2º Case
<?php
date_default_timezone_set('America/Sao_Paulo');
$date = new \DateTime('01/02/2016');
var_dump($date);
?>

Expected result:
----------------
1º Case
string(10) "01/02/2016"

2º Case
class DateTime#1 (3) {
  public $date =>
  string(26) "2016-02-01 00:00:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(17) "America/Sao_Paulo"
}

Actual result:
--------------
1º Case
02/01/2016

2º Case

Displays the following result
class DateTime#1 (3) {
  public $date =>
  string(26) "2016-01-02 00:00:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(17) "America/Sao_Paulo"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-16 04:54 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-01-16 04:54 UTC] requinix@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

http://php.net/manual/en/datetime.formats.date.php

#/#/# is interpreted to be either m/d/y or y/m/d. Use a different format for your string.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC