PHP date format and strtotime

pharkasbence

I would like to get a Y-m-d formatted date from a string like "28 January 1959".

I tried date("Y-m-d", strtotime($dateString)), but it returns 1970-01-01.

The weird thing is that, if I debug the above code with "28 January 1959" constant, it works, but if I replace the string with the variable which stores the same value, it returns 1970-01-01.

Any idea?

pharkasbence

The solution is remove special characters from the date string:

date("Y-m-d", strtotime(preg_replace('/[^A-Za-z0-9\-]/', '', $dateString)))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

format of date string for strtotime() function in php

From Dev

format of date string for strtotime() function in php

From Dev

How does PHP determine date format for a strtotime() call

From Dev

PHP date conversion using strtotime

From Dev

Formatting date using PHP strtotime

From Dev

Check a date interval with strtotime in php

From Dev

Using strtotime to format date() with AM/PM

From Java

What is the difference between compare two date as string with format (Y-m-d h:i:s) and two date with strtotime of date in php?

From Dev

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

From Dev

PHP date & strtotime adding 12 minutes?

From Dev

PHP Converting Integer to Date, reverse of strtotime

From Dev

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

From Dev

PHP strtotime() "noon" must go before date

From Dev

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

From Dev

strtotime is not working proper in php for future date?

From Dev

Php: Change language in date/strftime/strtotime

From Dev

PHP: strtotime revered return strange date?

From Dev

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

From Dev

PHP date returning blank for Year "2090" with strtotime

From Dev

strtotime is not working proper in php for future date?

From Dev

Strange behavior with the strtotime function passing a wrong date and time format

From Dev

Format date format php

From Dev

how to overwrite date to 1st of month php strtotime and date

From Dev

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

From Dev

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

From Dev

PHP strtotime error when convert some date string to datetime value

From Dev

PHP parse date with Timezone+Offset using strtotime()

From Dev

STRTOTIME to find current week, date for Monday and Saturday, PHP

From Dev

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

Related Related

  1. 1

    format of date string for strtotime() function in php

  2. 2

    format of date string for strtotime() function in php

  3. 3

    How does PHP determine date format for a strtotime() call

  4. 4

    PHP date conversion using strtotime

  5. 5

    Formatting date using PHP strtotime

  6. 6

    Check a date interval with strtotime in php

  7. 7

    Using strtotime to format date() with AM/PM

  8. 8

    What is the difference between compare two date as string with format (Y-m-d h:i:s) and two date with strtotime of date in php?

  9. 9

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

  10. 10

    PHP date & strtotime adding 12 minutes?

  11. 11

    PHP Converting Integer to Date, reverse of strtotime

  12. 12

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

  13. 13

    PHP strtotime() "noon" must go before date

  14. 14

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

  15. 15

    strtotime is not working proper in php for future date?

  16. 16

    Php: Change language in date/strftime/strtotime

  17. 17

    PHP: strtotime revered return strange date?

  18. 18

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

  19. 19

    PHP date returning blank for Year "2090" with strtotime

  20. 20

    strtotime is not working proper in php for future date?

  21. 21

    Strange behavior with the strtotime function passing a wrong date and time format

  22. 22

    Format date format php

  23. 23

    how to overwrite date to 1st of month php strtotime and date

  24. 24

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

  25. 25

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

  26. 26

    PHP strtotime error when convert some date string to datetime value

  27. 27

    PHP parse date with Timezone+Offset using strtotime()

  28. 28

    STRTOTIME to find current week, date for Monday and Saturday, PHP

  29. 29

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

HotTag

Archive