Andrade
Andrade

Reputation: 1199

PHP's function date() not working properly? (unexpected output)

I've noticed that one of my scripts that depend on the function date() fell into an infinite loop. While investigating the cause of this, I came up with a very simple an surprising test:

<?php
echo (date("Y-m-d H:i:s",1330221136)."\n\n");
echo (date("Y-m-d H:i:s",1330222036)."\n");

Since the first timestamp is smaller than the second, the first line was supposed to return an earlier datetime. However the out put for the code above is:

2012-02-25 23:52:16 

2012-02-25 23:07:16

Does anybody know about any malfunctioning of the function date() in PHP 5.3?

Upvotes: 2

Views: 169

Answers (2)

Jon
Jon

Reputation: 437854

This could legitimately happen if the clocks were turned one hour backwards at exactly 00:00 local time. So:

  1. Your code has a bug, because it does not allow for the possibility of this happening
  2. It seems that in your local time zone DST ended on 2012-02-26 00:00 (local time)
  3. Which lets us know that you are located in Brasil (props to Fluffeh for finding out!)

Upvotes: 6

JvdBerg
JvdBerg

Reputation: 21866

A copy/paste to my installation gives this as a result:

2012-02-26 02:52:16
2012-02-26 03:07:16

That seems fine to me.

Upvotes: 1

Related Questions