php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39668 date conversion failure
Submitted: 2006-11-28 22:43 UTC Modified: 2006-12-01 18:55 UTC
From: mehmety at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.0 OS: 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: mehmety at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-28 22:43 UTC] mehmety at gmail dot com
Description:
------------
In order to reproduce this bug, see the below source.

Using date and string to time ultimately causes the time to be reset for the year.  Seems like deviant behavior.




Reproduce code:
---------------
php -r 'for($x=0;$x<99;$x++){ $year=date("Y",strtotime("+$x years"));echo "$x $year\n"; } exit();'

Expected result:
----------------
{0...98}{today's year + {0...98} }

Actual result:
--------------
0 2006
1 2007
2 2008
3 2009
4 2010
5 2011
6 2012
7 2013
8 2014
9 2015
10 2016
11 2017
12 2018
13 2019
14 2020
15 2021
16 2022
17 2023
18 2024
19 2025
20 2026
21 2027
22 2028
23 2029
24 2030
25 2031
26 2032
27 2033
28 2034
29 2035
30 2036
31 2037
32 1969
33 1969
34 1969
35 1969
36 1969
37 1969
38 1969
39 1969
40 1969
41 1969
42 1969
43 1969
44 1969
45 1969
46 1969
47 1969
48 1969
49 1969
50 1969
51 1969
52 1969
53 1969
54 1969
55 1969
56 1969
57 1969
58 1969
59 1969
60 1969
61 1969
62 1969
63 1969
64 1969
65 1969
66 1969
67 1969
68 1969
69 1969
70 1969
71 1969
72 1969
73 1969
74 1969
75 1969
76 1969
77 1969
78 1969
79 1969
80 1969
81 1969
82 1969
83 1969
84 1969
85 1969
86 1969
87 1969
88 1969
89 1969
90 1969
91 1969
92 1969
93 1969
94 1969
95 1969
96 1969
97 1969
98 1969


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-28 22:52 UTC] tony2001@php.net
This means you (i.e. the timestamp) have reached the limit of integer. It's known problem and all *nix systems will face it in 2038. Not PHP problem, though.
 [2006-11-28 23:41 UTC] mehmety at gmail dot com
In that case, the PHP implimentation should not rely on a native function.
 [2006-12-01 18:55 UTC] derick@php.net
We don't rely on it for the date stuff, but PHP *itself* only handles normal signed integers. The following should work fine:

for ( $x = 0; $x < 99; $x++ )
{
    $year = date_format(date_create( "+$x years" ), "Y");
    echo "$x $year\n";
}

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC