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

zwitterion

I have a string $StartDate = "2015-09-23" (should be like yyyy-mm-dd). Than I make $UdtStart= strtotime($StartDate) that returns 1442980800; Well if I go to this link it return back "Wed, 23 Sep 2015 04:00:00 +0000". First, why do we have 04:00:00 added?

Than, if I do this $back=gmdate("Y-m-d H:i:s", ($UdtStart)); I will have "2015-09-26 04:00:00".

What am I missing?

$UdtStart=  strtotime($StartDate);
$back=gmdate("Y-m-d H:i:s", ($UdtStart));
paxdiablo
Wed, 23 Sep 2015 04:00:00 +0000

Note that +0000 on the end, that means the time is UTC. As per the PHP strtotime() doco:

Each parameter of this function uses the default time zone unless a time zone is specified in that parameter.

The gmdate is for Greenwich Mean Time (and really should be called something like utcdate nowadays), so you're asking for the data in a different foramt from what you gave it.

I'd be willing to bet money that you're in a timezone four hours removed from UTC, which is why you're seeing that.

If you want local time, use date() rather than gmdate(). The gmdate doco states:

Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

strtotime returning false date

From Dev

PHP - gmdate() and Large Integers

From Dev

PHP: Add some milliseconds to a date() with strtotime()

From Dev

PHP Converting Integer to Date, reverse of strtotime

From Dev

PHP date & strtotime adding 12 minutes?

From Dev

Different results for date() and gmdate()

From Dev

PHP strtotime() with date() issue with year field

From Dev

PHP Countdown timer for promotion using strtotime("future date/time") - strtotime("now") = countdown?

From Dev

3rd Last Day of the Month using PHP gmdate()

From Dev

Using next day in strtotime with PHP

From Dev

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

From Dev

String date to time in PHP - strtotime "loses hours"

From Dev

format of date string for strtotime() function in php

From Dev

PHP strtotime returning the wrong result on calculation

From Dev

PHP date conversion using strtotime

From Dev

Using Moment.js like PHP's date and strtotime

From Dev

PHP parse date with Timezone+Offset using strtotime()

From Dev

PHP strtotime returning always midnight

From Dev

PHP strtotime() "noon" must go before date

From Dev

Formatting date using PHP strtotime

From Dev

PHP date returning blank for Year "2090" with strtotime

From Dev

PHP Countdown timer for promotion using strtotime("future date/time") - strtotime("now") = countdown?

From Dev

PHP - Same Page Call Back Using Post

From Dev

Using next day in strtotime with PHP

From Dev

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

From Dev

PHP strtotime returning the wrong result on calculation

From Dev

Check a date interval with strtotime in php

From Dev

strtotime() function returning incorrect date

From Dev

PHP date format and strtotime

Related Related

  1. 1

    strtotime returning false date

  2. 2

    PHP - gmdate() and Large Integers

  3. 3

    PHP: Add some milliseconds to a date() with strtotime()

  4. 4

    PHP Converting Integer to Date, reverse of strtotime

  5. 5

    PHP date & strtotime adding 12 minutes?

  6. 6

    Different results for date() and gmdate()

  7. 7

    PHP strtotime() with date() issue with year field

  8. 8

    PHP Countdown timer for promotion using strtotime("future date/time") - strtotime("now") = countdown?

  9. 9

    3rd Last Day of the Month using PHP gmdate()

  10. 10

    Using next day in strtotime with PHP

  11. 11

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

  12. 12

    String date to time in PHP - strtotime "loses hours"

  13. 13

    format of date string for strtotime() function in php

  14. 14

    PHP strtotime returning the wrong result on calculation

  15. 15

    PHP date conversion using strtotime

  16. 16

    Using Moment.js like PHP's date and strtotime

  17. 17

    PHP parse date with Timezone+Offset using strtotime()

  18. 18

    PHP strtotime returning always midnight

  19. 19

    PHP strtotime() "noon" must go before date

  20. 20

    Formatting date using PHP strtotime

  21. 21

    PHP date returning blank for Year "2090" with strtotime

  22. 22

    PHP Countdown timer for promotion using strtotime("future date/time") - strtotime("now") = countdown?

  23. 23

    PHP - Same Page Call Back Using Post

  24. 24

    Using next day in strtotime with PHP

  25. 25

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

  26. 26

    PHP strtotime returning the wrong result on calculation

  27. 27

    Check a date interval with strtotime in php

  28. 28

    strtotime() function returning incorrect date

  29. 29

    PHP date format and strtotime

HotTag

Archive