- VolkomenJuist.nl - http://www.volkomenjuist.nl/blog -

Laravel and HTML 5 datetime component

I want to store all dates in UTC format into the database. To use HTML5 datetime-local element you have to do some conversion of datetimes. The HTML5 element expects a format of ‘2013-08-14T18:55’ (Y-m-d*H:i). In this post I’ll show you how I solved this.


{{ Form::input('datetime-local', 'matchdate', $matchday->matchdateHTML5()); }}


public function matchdateHTML5() {
        return $this->toHTML5Date($this->resource->matchdate);

public function toHTML5Date($dt) {
        return $dt->format('Y-m-d\TH:i');


//update or create function:
$matchday['matchdate'] = $this->convertHtml5dateToUTC(Input::get('matchdate'));

public function convertHtml5dateToUTC($dt) {
        $matchdate = Carbon::createFromFormat('Y-m-d*H:i', $dt, 'Europe/Amsterdam');
        return $matchdate->tz('UTC');
Buffer [1]