Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ap3twe's avatar

Carbon Changing date format

I am sending data through Soap. The XML format accepts date("Y-m-d). My request format is date("m-d-Y). I like the format in my app, so I don't want to change it, I only wanna change it for the API. I tried to use CarbonFromdate to format it but I am getting errors

 Unexpected data found. Unexpected data found.

tried this 1st

$dateWanted = $request->date_wanted;
 $timeZone = \date_default_timezone_get();
 $dateObject = Carbon::createFromFormat("m-d-Y", $dateWanted, $timeZone);

2nd Try

$dateWanted = $request->date_wanted;
$dateObject = Carbon::createFromFormat("m-d-Y", $dateWanted)->format('Y-m-d')
0 likes
7 replies
Sinnbeck's avatar

You dumping $dateWanted

Post the result here

dd($dateWanted);
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

There you go. It is / not -

$dateWanted = $request->date_wanted;
$dateObject = Carbon::createFromFormat("m/d/Y", $dateWanted)->format('Y-m-d')
Ap3twe's avatar

There I am!. I need glasses. The little detail. Thanks

Snapey's avatar

I'm surprised because XML dates should be in ISO8601 format which is YYYY/MM/DDThh:mm:ss

Ap3twe's avatar

Guys When I took the working code from controller to the job class, It fails. I am getting error

Laravel Horizon

InvalidArgumentException: Data missing in /Users/DesignPro/laravel/blog/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:537
{
job: null,
connection: null,
queue: null,
chainConnection: null,
chainQueue: null,
delay: {
date: "2019-12-03 16:55:45.006342",
timezone_type: 3,
timezone: "America/Vancouver"
},
chained: [
]
}

Laravel telescope Exception Message

Data missing

Ap3twe's avatar

I don't know maybe they following XSD Format.

This is the schema <s:element minOccurs="1" maxOccurs="1" name="DueDate" type="s:dateTime"/>

Please or to participate in this conversation.