0

I have a json data like this

{
    "DATE": "March, 05 2019 08:37:32 +0000",
    "EPOINTS": 100,
    "EXPIRATIONDATE": "July, 27 2046 08:42:33 +0000",
    "ID": 1,
    "AVAILABLEEPOINTS": 100,
    "TYPE": 1
}

I want to transfer the format of "DATE" to Y-m-d H:i:s,how should I do. The language is PHP 7.2 and framework is laravel5.7

melo yw
  • 31
  • 1
  • Ignore the accepted answer in the duplicate. The second answer using `DateTime::createFromFormat` is what you need. Format information can be found [here](https://www.php.net/manual/en/function.date.php) – Nick May 07 '19 at 08:11
  • extending @Nick comment, this should solve your problem `DateTime::createFromFormat("F, d Y h:i:s e", "March, 05 2019 08:37:32 +0000")->format('Y-m-d H:i:s')` – Sohel0415 May 07 '19 at 08:26
  • @Sohel0415 it should probably be `H` in the first format string too. – Nick May 07 '19 at 08:29
  • @Nick thanks, edited one `DateTime::createFromFormat("F, d Y H:i:s e", "March, 05 2019 08:37:32 +0000")->format('Y-m-d H:i:s')` – Sohel0415 May 07 '19 at 08:33

0 Answers0