Search code examples
phpdatetimecase-sensitive

Case sensitivity in PHP DateTime arguments


I'm creating DateTime objects using createFromFormat() method. I can't find it specified if the strings for format argument are case sensitive, where it comes to non-numerical parts. My question is about that matter - are the string arguments for DateTime::createFromFormat case sensitive?

E.g.

Is this:

DateTime::createFromFormat('M', 'May');
DateTime::createFromFormat('A', 'am');

equivalent to this:

DateTime::createFromFormat('M', 'may');
DateTime::createFromFormat('A', 'AM');

@Edit:

I see I should clear out the purpose of the question. Rules are not clearly stated in the documentation. Tests are obvious thing to do, but do not show the consistency between systems/versions etc., which is questionable when not specified. I'm asking if I've omitted anything that can prove how PHP works here. Thank you all for your time.


Solution

  • Yes it's case insensitive.

    $a = DateTime::createFromFormat('M', 'May');
    $b = DateTime::createFromFormat('M', 'may');
    
    var_dump($a == $b); //True