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));
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>