Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Content Editor Discussions /

Forum for content editors and CMS users.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

DateTimeField keeps converting times to AM


Go to End


4 Posts   178883 Views

Avatar
Dig

Community Member, 33 Posts

20 June 2013 at 3:15pm

In the time part of the date time field it always converts the time to AM no matter what is put in there. I notice it used strtotime so I've tried all sorts of creative entry to get a PM time but it simply doesn't work.

21:15 -> save -> 9:15:00 AM

9:15:00 PM -> save -> 9:15:00 AM

and plenty more.

This is in a dataobject managed by model admin, silverstripe 3.1 but we've tried 3, 3.0.5 and 3.1 in this process with the same results.

Any ideas, going a bit loopy here being stuck on such a simple seeming issue!

Cheers,

Avatar
Devlin

Community Member, 344 Posts

22 June 2013 at 12:14am

Edited: 22/06/2013 12:38am

I can reproduce this issue.

As a workaround, you can edit the time format to a 24h format.

$datetime = new DatetimeField('Datetime');
$datetime->timefield->setConfig('timeformat', 'H:mm');
// or
$time = new TimeField('Time');
$time->setConfig('timeformat', 'H:mm');

Edit:
Maybe related to #1713.

Avatar
tractorcow

Community Member, 63 Posts

28 June 2013 at 4:50pm

Pull request in https://github.com/silverstripe/silverstripe-framework/pull/2164

Hopefully this fixes the issue.

The problem was due to the TimeField mistakenly assuming times with am/pm were in ISO format (24 hour format) and converting them using this method. Sadly, this dropped the am/pm.

Avatar
Sam

Administrator, 690 Posts

7 July 2013 at 2:04pm

The fix mentioned above has been merged into the 3.1 branch and so will be included with 3.1.0-rc1