R.Wid R.Wid - 1 month ago 9
MySQL Question

php display date from sql

Hi Community



i'm currently working on a page, where i've got a problem with getting the date from the database table.

It looks like, i have now an own kinda array for the datetime columm.

print_r of my database:

$projwebt = $viewmanager->getViewPageProjwebtProjekte();
echo "<pre>";
print_r($projwebt);
echo "</pre>";


Output:

Array
(
[0] => viewPageProjwebtProjekte Object
(
[id] => 1
[projectnumber] => 1
[name] => Title
[progress] => 37
[status] => 1
[responsible] => user
[customer] => user
[definition] => 1
[effort] => 15
[priority] => 12
[startdate] => DateTime Object
(
[date] => 2016-11-25 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Belgrade
)

[targetdate] => DateTime Object
(
[date] => 2017-08-31 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Belgrade
)


works fine:

<?php
foreach ( $projwebt as $projobject )
{
?>
<tr class="<?=$projobject->status?>">
<th colspan="2"><h2><a href="#"><?=$projobject->name?></a></h2></th>
<th colspan="2"><h2><?=$projobject->definition?></h2></th>
<th colspan="2"><h2><?=$projobject->progress?>%</h2></th>
</tr>
<?php
}
?>


here it breaks, because of the startdate:

<tr>
<td class="responsible">Zuständig:</td>
<td class="responsibleName"><?=$projobject->responsible?></td>
<td class="effort">Aufwand:</td>
<td><?=$projobject->effort?> MT</td>
<td class="start">Start:</td>
<td class="startDate"><?=$projobject->startdate?></td>
</tr>


datamapper:

$pageProjwebtProjekte->startdate = $row['startdate'];
$pageProjwebtProjekte->targetdate = $row['targetdate'];


viewmanager:

$viewPageProjwebtProjekte->startdate = $value->startdate;
$viewPageProjwebtProjekte->targetdate = $value->targetdate;


when i pick the date to display (object oriented) it breaks.
so is there a way to pick the date element of the array startdate/ targetdate?
what do i have to set in my classes (viewmanager/ mapper...)?

I have no problem, when i try to display definition or effort and so on.

Thank you for having a look!

Answer

You have a DateTime object, not a regular array. Do something like this:

<?= $startdate = $projobject->startdate->format('Y-m-d'); ?>