Last Day of Year Date Bug?

Last Day of Year Date Bug?

am 31.12.2007 14:07:22 von ashore

Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?

date("Y")));?>

AS

Re: Last Day of Year Date Bug?

am 31.12.2007 14:18:34 von Jerry Stuckle

ashore wrote:
> Guys, the line below just returned "Dec 07" as the date for one month
> back from today. Hardly life-threatening, but any thoughts?
>
> > date("Y")));?>
>
> AS
>

Interesting. Looks like it may be a bug.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Last Day of Year Date Bug?

am 31.12.2007 14:18:34 von Jerry Stuckle

ashore wrote:
> Guys, the line below just returned "Dec 07" as the date for one month
> back from today. Hardly life-threatening, but any thoughts?
>
> > date("Y")));?>
>
> AS
>

Interesting. Looks like it may be a bug.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Last Day of Year Date Bug?

am 31.12.2007 15:08:15 von luiheidsgoeroe

On Mon, 31 Dec 2007 14:18:34 +0100, Jerry Stuckle =

wrote:

> ashore wrote:
>> Guys, the line below just returned "Dec 07" as the date for one month=

>> back from today. Hardly life-threatening, but any thoughts?
>> >> date("Y")));?>
>> AS
>>
>
> Interesting. Looks like it may be a bug.
>

Nope,
date('m')-1 =3D 11
date('d') =3D 31

31-11-2007 =3D 01-12-2007 as far as php is concerned.

Not 'end of a year' bug, but '31st of every month' bug (well, feature I'=
d =

say, I know what to expect), with a few bonus dates in march.
-- =

Rik Wasmus

Re: Last Day of Year Date Bug?

am 31.12.2007 15:27:43 von Jerry Stuckle

Rik Wasmus wrote:
> On Mon, 31 Dec 2007 14:18:34 +0100, Jerry Stuckle
> wrote:
>
>> ashore wrote:
>>> Guys, the line below just returned "Dec 07" as the date for one month
>>> back from today. Hardly life-threatening, but any thoughts?
>>> >>> date("Y")));?>
>>> AS
>>>
>>
>> Interesting. Looks like it may be a bug.
>>
>
> Nope,
> date('m')-1 = 11
> date('d') = 31
>
> 31-11-2007 = 01-12-2007 as far as php is concerned.
>
> Not 'end of a year' bug, but '31st of every month' bug (well, feature
> I'd say, I know what to expect), with a few bonus dates in march.

Ah, yes. Now I remember why I don't do it this way - it's been so long
I forgot.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Last Day of Year Date Bug?

am 31.12.2007 17:28:11 von ashore

Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive').

While correcting this will prbly break a lot of applications, mebbe
it's time for another date set of functions.

What DO you guys use to 'go back one month' reliably?

-AS

Re: Last Day of Year Date Bug?

am 31.12.2007 17:43:30 von luiheidsgoeroe

On Mon, 31 Dec 2007 17:28:11 +0100, ashore wrote:
> Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive')=
..

Well, it's something I rather depend on most of the time actually. How d=
o =

you propose it should handle '31-11-XXXX'? An error/exception perhaps, =

that would be justifiable. Just setting it back to 30-11 would be =

inexcusable.

> While correcting this will prbly break a lot of applications, mebbe
> it's time for another date set of functions.
>
> What DO you guys use to 'go back one month' reliably?

Depends on the use. In some cases, taking 01-12-2007 as one month before=
=

31-12-2007 is just what I want. In your context, why do you bother with =
=

the day part?

print date("M `y", mktime(0, 0, 0, date("m")-1, 1,date("Y")));
-- =

Rik Wasmus

Re: Last Day of Year Date Bug?

am 31.12.2007 17:46:03 von Tim Streater

In article
<063e7b54-e204-494e-b3fe-da540fddc6c0@l6g2000prm.googlegroups.com>,
ashore wrote:

> Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive').
>
> While correcting this will prbly break a lot of applications, mebbe
> it's time for another date set of functions.
>
> What DO you guys use to 'go back one month' reliably?

First we should ask - what does your question mean?

Does "go back one month" mean go back 31 days or does it mean "go to
same numbered day of previous month"?

Each definition has its problems. 2nd March minus 31 days takes you to
January. From 31st Dec, there *is no* same numbered day in previous
month.

Re: Last Day of Year Date Bug?

am 01.01.2008 02:32:17 von ashore

Fair question, but I meant literally what I'd asked: " ... back one
month ... ".

I wound up picking an arbitrary mid-month date (instead of 1 or 31) in
order to avoid the issues pointed out here, and backing off that by
one month. That got me the month number I needed. As they say,
"Works for me."

But thanks, guys; you've been helpful.

-AS
~~~_ /)~~~~~~~_ /)~~~~~~~_ /)~~~~~~~_ /)~~~~
>
> First we should ask - what does your question mean?
>
> Does "go back one month" mean go back 31 days or does it mean "go to
> same numbered day of previous month"?

Re: Last Day of Year Date Bug?

am 01.01.2008 04:31:31 von Larry Anderson

On Dec 31, 8:28 am, ashore wrote:
> Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive').
>
> While correcting this will prbly break a lot of applications, mebbe
> it's time for another date set of functions.
>
> What DO you guys use to 'go back one month' reliably?
>
> -AS

I use 1 as the day, if I want to find the last month, or a simple
$lastmonth = ($curmonth == 1,12, $curmonth -1);

The date with mktime is great for calculating out an arbitrary date
such as add 30 days to the current date, etc. It's not a bug, but a
great feature, if you understand how it works.

Here is some date arithmetic I posted that uses mktime, just to give
you an idea.

http://groups.google.com/group/comp.lang.php/browse_frm/thre ad/c8637f47a9537ff3/f3d94e81f2ec396a

Re: Last Day of Year Date Bug?

am 02.01.2008 19:09:41 von Steve

"ashore" wrote in message
news:d6ba01a0-1681-4377-a6d1-3d75297b7b59@s12g2000prg.google groups.com...
> Guys, the line below just returned "Dec 07" as the date for one month
> back from today. Hardly life-threatening, but any thoughts?
>
> > date("Y")));?>

it's a known bug.

php uses approximation methods to arrive at a date. most of the time it
works. essentially, php assumes an average of 30 days in every month. you
can use 12/30/2007 23:59:59 and subtract one month from it and get Nov
`07...

$date = strtotime('12/30/2007 23:59:59');
// echo date('M `y', $date); // Nov `07
// now, watch this...
$date = strtotime('+1 second', $date);
// you guessed it...Dec `07

i tend to avoid this problem by getting the first of the month and then
doing calculations from that (in similar contexts). php tends to correct the
30 day averaging bug when using the first of any month...at least i've never
had a problem like this when using the following:

$date = strtotime('12/31/2007 23:59:59');
$date = strtotime(date('m', $date) . '/01/' . date('Y', $date));
echo date('M `y', strtotime('-1 month', $date));

hth,

me

Re: Last Day of Year Date Bug?

am 02.01.2008 19:09:41 von Steve

"ashore" wrote in message
news:d6ba01a0-1681-4377-a6d1-3d75297b7b59@s12g2000prg.google groups.com...
> Guys, the line below just returned "Dec 07" as the date for one month
> back from today. Hardly life-threatening, but any thoughts?
>
> > date("Y")));?>

it's a known bug.

php uses approximation methods to arrive at a date. most of the time it
works. essentially, php assumes an average of 30 days in every month. you
can use 12/30/2007 23:59:59 and subtract one month from it and get Nov
`07...

$date = strtotime('12/30/2007 23:59:59');
// echo date('M `y', $date); // Nov `07
// now, watch this...
$date = strtotime('+1 second', $date);
// you guessed it...Dec `07

i tend to avoid this problem by getting the first of the month and then
doing calculations from that (in similar contexts). php tends to correct the
30 day averaging bug when using the first of any month...at least i've never
had a problem like this when using the following:

$date = strtotime('12/31/2007 23:59:59');
$date = strtotime(date('m', $date) . '/01/' . date('Y', $date));
echo date('M `y', strtotime('-1 month', $date));

hth,

me

Re: Last Day of Year Date Bug?

am 02.01.2008 20:01:03 von luiheidsgoeroe

On Wed, 02 Jan 2008 19:09:41 +0100, Steve wrote:

>
> "ashore" wrote in message
> news:d6ba01a0-1681-4377-a6d1-3d75297b7b59@s12g2000prg.google groups.com=
....
>> Guys, the line below just returned "Dec 07" as the date for one month=

>> back from today. Hardly life-threatening, but any thoughts?
>>
>> >> date("Y")));?>
>
> it's a known bug.
>
> php uses approximation methods to arrive at a date. most of the time i=
t
> works. essentially, php assumes an average of 30 days in every month. =
you
> can use 12/30/2007 23:59:59 and subtract one month from it and get Nov=

> `07...

This statement is utter nonsense. Why waste a perfectly good allready =

given explanation with garbage Steve? For your pleasure, the proof (than=
k =

god for february, be carefull about leap years..):

date_default_timezone_set('Europe/Amsterdam');
$date =3D mktime(12,0,0,3,1,2007);//1 march 2008
print date("M `y", mktime(0, 0, 0, date("m",$date)-1, date("d",$date), =

date("Y",$date)));
?>

According to your 'approximation method', this should return january, as=
=

31-01-2007 is 30 days before the 1st of march. It does not. The real =

answer is still: 'if in mktime the nth day of a month doesn't exist, PHP=
=

will assume you mean the (n-)th of the next month'.(Or in=
=

case of negative numbers, the (n+)th of the previous mont=
h. =

Similarly:

date_default_timezone_set('Europe/Amsterdam');
//march the 63 is assumed to be may 2nd
print date("d M `y", mktime(0, 0, 0, 3, 63, 2007));
//february the 0th is assumed to be january the 31st
print date("d M `y", mktime(0, 0, 0, 2, 0, 2007));
//april the -1th is assumed to be march the 30th
print date("d M `y", mktime(0, 0, 0, 4, -1, 2007));
//the 0th month is assumed to be december
print date("d M `y", mktime(0, 0, 0, 0, 1, 2007));
//the -1th month is assumed to be november
print date("d M `y", mktime(0, 0, 0, -1, 1, 2007));
?>

If you have imagined an answer to a question, please be sure it's the =

right one before spreading it around.

> i tend to avoid this problem by getting the first of the month and the=
n
> doing calculations from that (in similar contexts).

Which was allready suggested.
-- =

Rik Wasmus

Re: Last Day of Year Date Bug?

am 02.01.2008 20:52:52 von unknown

Post removed (X-No-Archive: yes)

Re: Last Day of Year Date Bug?

am 02.01.2008 21:11:21 von Michael Fesser

..oO(Steve)

>"ashore" wrote in message
>news:d6ba01a0-1681-4377-a6d1-3d75297b7b59@s12g2000prg.googl egroups.com...
>> Guys, the line below just returned "Dec 07" as the date for one month
>> back from today. Hardly life-threatening, but any thoughts?
>>
>> >> date("Y")));?>
>
>it's a known bug.

Wrong.

>php uses approximation methods to arrive at a date. most of the time it
>works. essentially, php assumes an average of 30 days in every month.

Wrong again. PHP knows exactly how many days each month has, it just
uses its own way to fix invalid dates like YYYY-11-31 for example.

>you
>can use 12/30/2007 23:59:59 and subtract one month from it and get Nov
>`07...
>
>$date = strtotime('12/30/2007 23:59:59');
>// echo date('M `y', $date); // Nov `07

2007-12-30 - 1m = 2007-11-30

>// now, watch this...
>$date = strtotime('+1 second', $date);
>// you guessed it...Dec `07

2007-12-31 - 1m = 2007-11-31 = 2007-12-1

So where's the problem? PHP's date handling is described in detail in
the manual. It works as intended.

Micha

Re: Last Day of Year Date Bug?

am 02.01.2008 21:11:21 von Michael Fesser

..oO(Steve)

>"ashore" wrote in message
>news:d6ba01a0-1681-4377-a6d1-3d75297b7b59@s12g2000prg.googl egroups.com...
>> Guys, the line below just returned "Dec 07" as the date for one month
>> back from today. Hardly life-threatening, but any thoughts?
>>
>> >> date("Y")));?>
>
>it's a known bug.

Wrong.

>php uses approximation methods to arrive at a date. most of the time it
>works. essentially, php assumes an average of 30 days in every month.

Wrong again. PHP knows exactly how many days each month has, it just
uses its own way to fix invalid dates like YYYY-11-31 for example.

>you
>can use 12/30/2007 23:59:59 and subtract one month from it and get Nov
>`07...
>
>$date = strtotime('12/30/2007 23:59:59');
>// echo date('M `y', $date); // Nov `07

2007-12-30 - 1m = 2007-11-30

>// now, watch this...
>$date = strtotime('+1 second', $date);
>// you guessed it...Dec `07

2007-12-31 - 1m = 2007-11-31 = 2007-12-1

So where's the problem? PHP's date handling is described in detail in
the manual. It works as intended.

Micha