Pida

Store date (dd.mm.yyyy) as timestamp

Posted 7 months ago by Pida

I need help with refactoring a form. There's one issue left: I'd like to change a date input to dd.mm.yyyy format as the app is in German.

The JavaScript part (I use a date picker) is working fine, but I can't get Laravel to store the correct timestamp:

// $request->entry_date is '10.12.2017' (December 10th, 2017)
$request->entry_date = Carbon::createFromFormat('d.m.Y', $request->entry_date);
// In DDB after update: 2010-12-20 17:00:00
// Expected after update: 2017-12-10 (plus whatever time Carbon adds, I just care about the date)
$client->update($request->all());

The 17:00 in the timestamp makes me suspect Carbon interprets the third and fourth digits of the year as hour, but I checked with the docs: Y is year (four digits), m is month (2 digits), d ist day (2 digits).

What's wrong with my code?

Thanks, Pida

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.