Search code examples
phplocalizationstrtotime

strtotime With Different Languages?


Does strtotime only work in the default language on the server? The below code should resolve to august 11, 2005, however it uses the french "aout" instead of the english "aug".

Any ideas how to handle this?

<?php
    $date = strtotime('11 aout 05');
    echo date('d M Y',$date);
?>

Solution

  • From the docs

    Parse about any English textual datetime description into a Unix timestamp

    Edit: Six years down the road now, and what was meant to be a side-note about why strtotime() was an inappropriate solution for the issue at hand became the accepted answer 😲

    To better answer the actual question I want to echo Marc B's answer: despite the downvotes, date_create_from_format, paired with a custom Month interpreter will provide the most reliable solution

    However it appears that there is still no silver-bullet for international date parsing built-in to PHP for the time being.