March 6, 2013

convert date format within a webservice php context

Question by Peter van der Lely

I am consuming a webservice in php. The piece of code below gives me the following result with regard to the date notation:

Begindatum : 2012-07-02T00:00:00. I would like to have that in a European format like:

Begindatum : 02-07-2012. I’ve been trying to imlement the standard solution:

Convert date format yyyy-mm-dd => dd-mm-yyyy

but without succes. Help is appreceated.

 foreach($array as $k=>$v){
 print "
 <tr>
      <td>
            <ul>
                <li><b>Naam         : {$v->Naam}</b></li>
                <li><b>Status       : {$v->Status}</b></li>
                <li><b>Aanbieder    : {$v->VerstrekkerNaam}</b></li>
                <li><b>Bedrag       : {$v->Bedrag}</b></li>
                <li><b>Begindatum   : {$v->Begindatum}</b></li>

            </ul>
      </td>
</tr>

Answer by Starx

You can try this

$d = "2012-07-02T00:00:00";
echo $newDate = date("d-m-Y",strtotime($d));

Demo

In your code you may apply it as

foreach($array as $k=>$v){
 print "
 <tr>
      <td>
            <ul>
                <li><b>Naam         : {$v->Naam}</b></li>
                <li><b>Status       : {$v->Status}</b></li>
                <li><b>Aanbieder    : {$v->VerstrekkerNaam}</b></li>
                <li><b>Bedrag       : {$v->Bedrag}</b></li>
                <li><b>Begindatum   : {" . date("d-m-Y",strtotime($v->Begindatum)) ."}</b></li>
            </ul>
      </td>
</tr>

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!