-2
I need to format a value for date... I search for the link of the following value:
20181107
No case would be 07/11/2018, today. I need to take this value and format in format 2018-11-07
, I tried it this way:
date('Y-m-d', strtotime('20181107'));
However, in some cases he puts the day in the place of the month, there wanted a solution to this or just a code that inserted a hyphen after 4 digits and after 6 digits, it would be simpler too.
Can you tell in which cases you happen to put the day in the place of the month? I could not reproduce.
– Jorge B.
It may not apply to you (you don’t want to use it for many reasons), but if you have to deal with dates often, it might be worth a look at the library Carbon. Even she is the standard lib adopted by Laravel.
– nmindz
"Put the day in place of the month"... Who does it? PHP or url return?
– Wallace Maxters
That ? How to invert dates in PHP, regardless of format?
– rray