Emanuele Paolini
Emanuele Paolini

Reputation: 10162

cakephp datetime formatter not parsing time part

I have an input which gives this string to be converted to a datetime field (this is the default format for <input type='datetime-local'> elements):

'2020-04-19T18:00'

I have configured the parser with:

Type::build('datetime')->useLocaleParser()->setLocaleFormat('yyyy-MM-ddTHH:mm');

however what I get in the datetime field is:

'datetime' => object(Cake\I18n\FrozenTime) {
    'time' => '2020-04-19 00:00:00.000000+00:00',
    'timezone' => 'UTC',
    'fixedNowTime' => false

}

Nothing changes if I use 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm': I always get a value 00:00:00 for the time portion.

Upvotes: 0

Views: 233

Answers (1)

ndm
ndm

Reputation: 60453

There's small problem in your pattern, you need to escape regular text, as all letters bewteen aA and zZ are reserved as pattern letters, ie the T needs to be in single quotes like this:

"yyyy-MM-dd'T'HH:mm"

See also

Upvotes: 1

Related Questions