I have been wondering how I can change my date Format in PHP. Seemingly as I have been very familiar with JAVA and JSP all thru my working life, I thought moving into php would be easy. So then I got myself involved into a simple assignment which I came up myself.
Though searching for PHP help sometimes is a bit pain in the ass as I got to learn it all once again especially the syntax. One great function is the explode() function, but now though, I had problem displaying the date in the right function.
Unlike Java, I can use the SimpleDateFormat class to change my date into my desired format but not in php.
SimpleDateFormat dtFormat = new SimpleDateFormat(‘dd-MM-yyyy’);
PHP looks like no such function and there are loads out there using explode() function and recombine them later. There has to be a shorter way.
I finally found it and here’s the solution to it here instead.
Let’s say if you retrieve the date data from mySQL it will be like 2009-04-03 which is format. Now I would like to make it 03-04-2009. Solution is stated below.
echo date(‘d-m-Y’,strtotime(dateVariable));
By using echo I can print out the date in that desired format. Looks like I have a long way to go in my PHP research and play.
Hmm .. for comparison sake, in .NET the code would be:
date.parse (“dd-mm-yyyy”)
hey, its very helpful article. nice post.
Thanks so much!
Thanks so much for this.
just what I’m looking for. Thanks 🙂
Than Q so puch for your posting … Im googling this kind of date format for a long time .. finally i got it from you