1

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 column.

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!

4
  • 1
    <?= is shorthand for <?php echo and perfectly valid Commented Oct 27, 2016 at 11:53
  • Try using format method() php.net/manual/en/datetime.format.php Commented Oct 27, 2016 at 11:54
  • Somewhere your code is converting the datetime from the database to a php DateTime object. That does not happen automatically, you are doing that yourself and you can format its value using the format() method. Commented Oct 27, 2016 at 11:55
  • Thank you very much for these informations! helped me a lot for understanding! Commented Oct 27, 2016 at 12:26

2 Answers 2

3

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

This was exactly the solution for my problem, thank you very much! will keep that in mind, for the next time.
3

If you want to echo the date from a DateTime object you should use the format method.

Ex. echo $projobject->startDate->format('Y-m-d');

You can see the documentation here: http://php.net/manual/es/class.datetime.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.