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
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: ualison dot aguiar at gmail dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 22:01:28 2024 UTC