Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 50
    Curious as to why this isn't the accepted answer... This is much more flexible than relying on the quirks of the strtotime() function. Commented Dec 4, 2012 at 21:43
  • 11
    It's important to point that php DateTime class is available since PHP version 5.2 and createFromFormat since 5.3 Commented Sep 23, 2013 at 19:10
  • 16
    As with every function, you should check if it meets minimum version you must support. But PHP 5.2 EOL was Jan 2011. Nobody should be running it any more; catering to those people is just enabling them to run outdated, insecure software. Commented Sep 24, 2013 at 2:24
  • @Matthew yes, correct. But you never now, even today I found a PHP4.1 version still installed ... Commented Nov 26, 2018 at 16:45
  • 1
    I agree with commenters saying this should be the accepted answer, unless for some godforsaken reason you happen to be stuck with PHP 4 point something. In that case, date formatting ought to be the least of your worries. Commented Apr 25, 2023 at 17:48