Different results for date() and gmdate()

berliner

I found something I can't really explain, maybe someone here can give me a hint.

I have the following test code, that prints 2 formatted timestamps, one for the 31.03.2013 and one for 31.03.2014, using date()and gmdate():

<?php

function print_date($timestamp, $year) {
  // Add timezone offset for germany
  $timestamp += 3600;
  print "in $year\n";
  print "date:   " . date('d.m.Y H:i:s', $timestamp) . "\n";
  print "gmdate: " . gmdate('d.m.Y H:i:s', $timestamp) . "\n";
  print "\n";
}

$end_2013 = 1364684400; // 31.03.2013
$end_2014 = 1396216800; // 31.03.2014
print_date($end_2013, '2013');
print_date($end_2014, '2014');

print "Default timezone: " . date_default_timezone_get() . "\n";

The result surprises me:

in 2013
date:   31.03.2013 01:00:00
gmdate: 31.03.2013 00:00:00

in 2014
date:   31.03.2014 01:00:00
gmdate: 30.03.2014 23:00:00

Default timezone: Europe/Berlin

Where does the difference in 2014 come from? My first thought is daylight savings time, but why doesn't that have an effect in 2013? Why are there 2 hours difference in 2014 but only 1 hour difference in 2013?

Mark Baker

Daylight savings for Berlin starts at

2013 Sunday, 31 March, 02:00 
2014 Sunday, 30 March, 02:00 

Your specified time value for each date is 00:00 on that date, so for 2013 Sunday, 31 March it is before 2am, so no daylight savings; for 2014 it is after 2am on 30th March

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

date() and gmdate() return different results

From Dev

php, normal date is correct, but gmdate is not accurate

From Dev

php, normal date is correct, but gmdate is not accurate

From Dev

date returning different results in different versions of php

From Dev

Using strtotime() PHP and revert back trough gmdate() is not returning same date

From Dev

Add date in php gives different results

From Dev

Carbon 2 Date parsing returns different results

From Dev

Why are these 2 date commands giving different results?

From Dev

Why hwclock and date display different results and how to correct it

From Dev

Different results for same date string using lubridate package in R

From Dev

why to_char and to_date returns different results

From Dev

SimpleDateFormat parse and format on same date string gives different results

From Dev

Different results for same date string using lubridate package in R

From Dev

new Date() on javascript gives different result when comparing the results

From Dev

Trying to find latest date in an array using max but getting different results

From Dev

Android/Java - Calculate date difference shows different results

From Dev

JavaScript new Date(string) returns different results on exactly identical date strings

From Dev

TO_CHAR and TO_DATE giving different results.How to achieve the TO_CHAR functionality using TO_DATE?

From Dev

Using two date comparisons instead of date range query gives different results in MongoDB

From Dev

Different Results on Different System

From Dev

PHP - gmdate() and Large Integers

From Dev

how to output results of table field from a date range on different tables SQL

From Dev

Two Different Results When Subtracting Two Date Between my Computer and my Linux Server

From Dev

Switched Windows Server machines and generating date string in a batch file produces different results

From Dev

iOS Swift Same code results in different date formats when run on iPad and iPhone

From Dev

SQL query different results between workbench and PHP script in the same date range

From Dev

DecimalFormat results in two different results on different machines

From Dev

DecimalFormat results in two different results on different machines

From Dev

METIS: different results on different OS

Related Related

  1. 1

    date() and gmdate() return different results

  2. 2

    php, normal date is correct, but gmdate is not accurate

  3. 3

    php, normal date is correct, but gmdate is not accurate

  4. 4

    date returning different results in different versions of php

  5. 5

    Using strtotime() PHP and revert back trough gmdate() is not returning same date

  6. 6

    Add date in php gives different results

  7. 7

    Carbon 2 Date parsing returns different results

  8. 8

    Why are these 2 date commands giving different results?

  9. 9

    Why hwclock and date display different results and how to correct it

  10. 10

    Different results for same date string using lubridate package in R

  11. 11

    why to_char and to_date returns different results

  12. 12

    SimpleDateFormat parse and format on same date string gives different results

  13. 13

    Different results for same date string using lubridate package in R

  14. 14

    new Date() on javascript gives different result when comparing the results

  15. 15

    Trying to find latest date in an array using max but getting different results

  16. 16

    Android/Java - Calculate date difference shows different results

  17. 17

    JavaScript new Date(string) returns different results on exactly identical date strings

  18. 18

    TO_CHAR and TO_DATE giving different results.How to achieve the TO_CHAR functionality using TO_DATE?

  19. 19

    Using two date comparisons instead of date range query gives different results in MongoDB

  20. 20

    Different Results on Different System

  21. 21

    PHP - gmdate() and Large Integers

  22. 22

    how to output results of table field from a date range on different tables SQL

  23. 23

    Two Different Results When Subtracting Two Date Between my Computer and my Linux Server

  24. 24

    Switched Windows Server machines and generating date string in a batch file produces different results

  25. 25

    iOS Swift Same code results in different date formats when run on iPad and iPhone

  26. 26

    SQL query different results between workbench and PHP script in the same date range

  27. 27

    DecimalFormat results in two different results on different machines

  28. 28

    DecimalFormat results in two different results on different machines

  29. 29

    METIS: different results on different OS

HotTag

Archive