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

Syrine123's avatar

How Can I Resolve "Incorrect datetime value: 'Wed Aug 24 2022 00:00:00 GMT+0200"

I'm using laravel8 API with reactjs Frontend I don't know How to set dateTime Format in laravel part to Central European Summer Time. Any Suggestion Please this is my migration code : $table->dateTime('visit_issue_date');

0 likes
20 replies
tykus's avatar

You can use Carbon to parse the incoming string to allow you pass a valid Y-m-d H:i:s string format to the database

$date = \Carbon\Carbon::parse($request->input('visit_issue_date'));

If you need to convert to equivalent UTC time (for storage)

$date = \Carbon\Carbon::parse($request->input('visit_issue_date'))->setTimezone('UTC');
1 like
Syrine123's avatar

Now I get this error : "Could not parse 'Mon Apr 04 2022 11:32:56 GMT+0200" @tykus

Syrine123's avatar
            $visitor->visit_issue_date=\Carbon\Carbon::parse($request->input('visit_issue_date'));

@tykus

tykus's avatar

@Syrine123 okay... so you have a Visitor instance, and you're setting a value from the parsed string. This should be working, no?

Syrine123's avatar

@tykus Yes But I should parse it into central europeen summer time not UTC.. I think the problem is in the timezone

tykus's avatar

@Syrine123 but you are not modifying the timezone in the example above - for the given input:

Wed Aug 24 2022 00:00:00 GMT+0200

what is being stored in the database?

Syrine123's avatar

@tykus I juste declare it as datetime: $table->dateTime('visit_issue_date');

tykus's avatar

@syrine123 do you prefer to store the date and time as UTC or CET in the database???

Syrine123's avatar

@tykus I want it GMT +0200 as in the frontend because I can't change it in the front so I have to make it compatible with the frontend

Syrine123's avatar

I found this solution : $visitor->visit_issue_date=date('Y-m-d', strtotime($request->input('visit_issue_date')));

But In the frontend it works correctly only for current date but for other input dates it displayed 1970-01-01 as output @tykus @ralston69 do you have any idea how to make .toISOString in laravel ?

tykus's avatar

@Syrine123 how are you passing the date to the view - is it a Carbon instance? How are you using the date in the view?

Syrine123's avatar

@tykus I use a react-flatpickr. The current date worked correctly jecause I declare it as a new Date(). ToISOString() but the others not because Idon't know how to make it iso

Syrine123's avatar

@tykus <Col sm='12' className='mb-1'> <Label className='form-label' for='visit_issue_date'> Visit Issue Date <span className='text-danger'>* </Label> <Flatpickr className='form-control' value={visit_issue_date} id='visit_issue_date' options={{ dateFormat: 'Y-m-d', }} onChange = {(date) => { setIssueDate(date) } } /> </Col>

Please or to participate in this conversation.