Jump to content

date function error ?


ddd119

Recommended Posts

Here is the code:

 

print date("Y m d H",1099198800) ."\n";

print date("Y m d H",1099202400) ."\n";

 

and here is the output:

 

2004 10 31 01

2004 10 31 01

 

I believe it is not rigth!

 

I can reproduce the result on a couple PHP installations between PHP 4.2 and PHP 5.2;

I cannot reproduce it with another year, month or day.

 

Help Please ?

Link to comment
Share on other sites

mine appears to be right on. go backwards:

 

echo mktime(23,0,0,10,30,2004)."<BR>";
echo mktime(00,0,0,10,31,2004)."<BR>";

 

even better:

 

<?
echo mktime(23,0,0,10,30,2004)."<BR>";
echo mktime(00,0,0,10,31,2004)."<BR>";

print date("Y m d H",mktime(23,0,0,10,30,2004)) ."<BR>";
print date("Y m d H",mktime(00,0,0,10,31,2004)) ."<BR>";
?>

 

output:

 

1099198800

1099202400

2004 10 30 23

2004 10 31 00

 

Link to comment
Share on other sites

lokk at this:

<?php

print date("Y m d H",1099198800) ."\n";

print date("Y m d H",1099202400) ."\n";

 

print mktime(01,0,0,10,31,2004) ."\n";

?>

 

 

and the output is:

 

2004 10 31 01

2004 10 31 01

1099198800

 

so the second line is wrong.

You tried with another time and is working ok.

As I said, any other time seems ok.

 

 

 

 

Link to comment
Share on other sites

my output:

 

2004 10 30 23

2004 10 31 00

1099206000

 

are you using windows?

 

my second example used the exact same times you used, 1099198800 and 1099202400. here, it's changed to make it better:

 

<?

echo mktime(23,0,0,10,30,2004)."<BR>";

echo mktime(00,0,0,10,31,2004)."<BR>";

 

print date("Y m d H",1099198800) ."<BR>";

print date("Y m d H",1099202400) ."<BR>";

?>

 

Link to comment
Share on other sites

i don't get those results here. are you using Windows PHP or *nix?

 

my output from your first post is this:

 

2004 10 30 23

2004 10 31 00

 

so, i'm not getting the same date/time. the same day, yes, but 1 hour off.

 

1099202400 - 1099198800 = 3600 seconds = 1 hour. there appears to be something wrong with your system

 

Link to comment
Share on other sites

Look at the affect of different timezones:

<?php
date_default_timezone_set('America/New_York');

echo '<h1>' . date_default_timezone_get() . "</h1>\n";
print date("Y m d H:i:s",1099198800) ."<br />\n";
print date("Y m d H:i:s",1099202400) ."<br />\n";

echo '<br /><br />';

date_default_timezone_set('Europe/London');
echo '<h1>' . date_default_timezone_get() . "</h1>\n";
print date("Y m d H:i:s",1099198800) ."<br />\n";
print date("Y m d H:i:s",1099202400) ."<br />\n";

echo '<br /><br />';

date_default_timezone_set('Australia/Sydney');
echo '<h1>' . date_default_timezone_get() . "</h1>\n";
print date("Y m d H:i:s",1099198800) ."<br />\n";
print date("Y m d H:i:s",1099202400) ."<br />\n";

?>

 

Output:

America/New_York
2004 10 31 01:00:00
2004 10 31 01:00:00


Europe/London
2004 10 31 05:00:00
2004 10 31 06:00:00


Australia/Sydney
2004 10 31 16:00:00
2004 10 31 17:00:00

 

The result you are recieve is infact correct. However I'm not sure why for America timezone the dates are the same.

Link to comment
Share on other sites

The dates are the same due to Day Light Savings time. At 2am, time moved back to 1am. If you include the GMT offset in the output you will see:

 

<?php
  print date('r',1099198800);
  print date('r',1099202400);
?>
Sun, 31 Oct 2004 01:00:00 -0400
Sun, 31 Oct 2004 01:00:00 -0500

Link to comment
Share on other sites

Guys, thanks so much for help ...

I don't think it is a timezone problem.

Maybe I did not make my point quite clear:

here is the same code modified so it does not depends on the timezone:

 

print date("Y m d H",mktime(01,0,0,10,31,2004)) ."\n";

 

print date("Y m d H",mktime(01,0,0,10,31,2004) +3600) ."\n";

 

and the output:

2004 10 31 01

2004 10 31 01

 

it is obvious so wrong....

 

 

To the previous question: it first happened on a Linux server (PHP 4.3.9)

and I reproduce it on XP (PHP 5.3)

Link to comment
Share on other sites

Did you see my post?

 

The dates are the same due to Day Light Savings time. At 2am, time moved back to 1am. If you include the GMT offset in the output you will see:

 

<?php
  print date('r',1099198800);
  print date('r',1099202400);
?>
Sun, 31 Oct 2004 01:00:00 -0400
Sun, 31 Oct 2004 01:00:00 -0500

 

It's also clear if you use the DST switch for date:

 

print date("Y m d H I",mktime(01,0,0,10,31,2004)) ."\n";
print date("Y m d H I",mktime(01,0,0,10,31,2004) +3600) ."\n";

and the output:

2004 10 31 01 1
2004 10 31 01 0

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.