tftd
tftd

Reputation: 17042

Is it me or there's a bug in PHP DateTime?

I've just encountered on a problem I never though would exist. I have a form that submits dates in the following format 04/28/2013 11:00. On the user front-end I'm using jquery datetimepicker and on the backend I have php to process the form.

Doing some testing I found out that DateTime in php does not throw an exception when the time is broken. For example this 04/28/2013 11:00123123 would not trigger an exception - instead DateTime returns now time. In my case the date is not related to now - it's a specific date & time in the future.

In my opinion DateTime should return an exception rather than now time. Is it me, or this is a bug?

Edit: I'm using php 5.3.23

Upvotes: 0

Views: 769

Answers (1)

hek2mgl
hek2mgl

Reputation: 158060

Posting this as an answer as the comments wouldn't fit for it.

<?php

new DateTime('04/28/2013 11:00123123');

I'm getting:

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (04/28/2013 11:00123123) at position 16 (1): Double time specification' in ...

Exception: DateTime::__construct(): Failed to parse time string (04/28/2013 11:00123123) at position 16 (1): Double time specification in ...
Call Stack:
    0.0001     635184   1. {main}() 
    0.0001     636048   2. DateTime->__construct() 

I'm using PHP5.3.10. And you?

Upvotes: 1

Related Questions