Edit report at https://bugs.php.net/bug.php?id=62194&edit=1

 ID:                 62194
 Updated by:         ras...@php.net
 Reported by:        kg_emopunk at yahoo dot com
 Summary:            Bug on using strtotime to date
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux/ Windows
 PHP Version:        5.3.13
 Block user comment: N
 Private report:     N

 New Comment:

There isn't really a bug here. If you try this same script tomorrow you will 
get 
your expected output. strtotime() will use the current date for any missing 
info, so since today is the 31st of the month, it will try to get the 31st of 
each month. Any month that doesn't have 31 days will end up giving you the 
appropriate offset into the following month. This is consistent with relative 
date offsets and related to the standard Unix approach to handling impossible 
dates described here:

http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-
strings.html#SEC125

The real solution is to specify a day in the month if you want your code to 
work 
reliably. As in strtotime("$key 1")


Previous Comments:
------------------------------------------------------------------------
[2012-05-31 05:49:20] kg_emopunk at yahoo dot com

Description:
------------
---
>From manual page: http://www.php.net/function.strtotime
---

There is a slight bug using strtotime to date.
When the strtotime parameter is only Month, the output adding date syntax is 
incorrect.

Incorrect month outputs:
 Feb / February
 Apr / April
 Jun / June
 Sep / September
 Nov / November

The solution for this is to add a day or a year. 
e.g ( date("F",strtotime($month." ".$day)); )


Test script:
---------------
<?php
$s=array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$s1=array('January','February','March','April','May','June','July','August','September','October','November','December');

echo "<h4> 3 Letters Months </h4>";
foreach ($s as $key) {
  echo date("F",strtotime($key))."<br>";
}
echo "<h4> Full Text Months </h4>";
foreach ($s1 as $key) {
  echo date("F",strtotime($key))."<br>";
}
?>

Expected result:
----------------
3 Letters Months

January
February
March
April
May
June
July
August
September
October
November
December

Full Text Months

January
February
March
April
May
June
July
August
September
October
November
December

Actual result:
--------------
3 Letters Months

January
March
March
May
May
July
July
August
October
October
December
December


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62194&edit=1

Reply via email to