-1
$opening_date = '2020-01-01T00:00:00+08:00'         
$opening_date = date('Y-m-d 00:00:00', strtotime($opening_date));

PHP 5.6 result

2020-01-01 00:00:00

PHP 8.0 result

2019-12-31 00:00:00

Hi, I'm doing date converting with different version but have no idea why the code is same but result is different. The expected result shall be 2020-01-01 00:00:00 but in PHP8.0 it minus 1 day. Is there any solution about this?

jaydon.T
  • 17
  • 4
  • Can't [reproduce](https://3v4l.org/BJJV2) your error, is this all the code? can you make sure the timezone setting are the same on both version. – catcon Mar 25 '21 at 04:45
  • date function vs DateTime object: https://stackoverflow.com/questions/20288789/php-date-with-timezone/20289096 – Alexey Inkin Mar 25 '21 at 04:49

1 Answers1

0

This is not the issue related to version of PHP. I think you have not defined the timezone correctly.

This is the code that I have written. (Assuming New_York as timezone)

<?php
$timezone = "America/New_York";
$opening_date = '2020-01-01T00:00:00+08:00';
echo $opening_date = date('Y-m-d 00:00:00', strtotime($opening_date));
?>

& in both versions of PHP, It is showing me the same output.

PHP Version: 8.0.0 http://sandbox.onlinephpfunctions.com/code/66fd1dd83dafbc1749383990effbb8586c922c15

PHP Version: 5.6.2 http://sandbox.onlinephpfunctions.com/code/66fd1dd83dafbc1749383990effbb8586c922c15

John Doe
  • 1,401
  • 1
  • 3
  • 14