How to parse a date in php

Getting back to php from Java has become a good experience, php allows you to develop faster but without (in my opinion) the same robustness that you have in Java because of the strong typing or at least that is what happens if you are not really really sure what are you doing (because it is easier to let holes in php code than in java code). However, it is cool, let’s look at how to parse a date in php:

we have a date as a string

$stringDate = "2009-12-12";

strtotime() will try to find out the format, in this case it won’t have any problem because it is an easy one, but it can automatically parse harder things…

$dateAsLong = strtotime($stringDate);

now we have the date as a long, and we can print it with another format.

echo date("d/m/Y", $dateAsLong );

One thought on “How to parse a date in php”

Leave a Reply

Your email address will not be published.

WP2Social Auto Publish Powered By :