PHP Issues with DateTime in array from JIRA api





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm trying to get data out of JIRA and into a table. I have got the API request working and I have got almost all the data out of JIRA and into the table that I need, I just can't seem to get the created date out as it is in a datetime object within the array and doesn't have a proper format.



    foreach ($ret->issues as $issue)
{
$date = new DateTime($issue->fields->created->date);
$date = $date->format('Y-m-d');
echo '<tr>
<td>'.$issue->fields->status->name.'</td>
<td>'.$date.'</td>
<td>'.$issue->fields->priority->name.'</td>
<td>'.$issue->fields->summary.'</td>
<td>'.$issue->fields->assignee->displayName.'</td>
</tr>';
}


That is the PHP code for building the table, as you can see I've tried to format it with DateTime.



Here is the array if I die on $issue->fields->created



    object(DateTime)#318 (3) {
["date"]=>
string(26) "2018-10-22 12:47:02.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-04:00"
}


I just can't seem to get that data out as $issue->fields->created->date shows me:



PHP Fatal error:  Cannot use object of type DateTime as array


Which is why I tried to format it as above. Now I get:



PHP Notice:  Undefined property: DateTime::$date


Any ideas?










share|improve this question

























  • $date = $issue->fields->created; ? It appears to already be a DateTime object.

    – rickdenhaan
    Nov 23 '18 at 21:12











  • It does, I need to use that data but I don't know how to.

    – Pete Wall
    Nov 23 '18 at 21:21











  • Looks like you could just use $issue->fields->created->format('Y-m-d') inside your echo

    – rickdenhaan
    Nov 23 '18 at 21:25











  • @rickdenhaan, please set that as the answer and I will vote for it! I had tried this method but I did $issue->fields->created->date->format('Y-m-d') which failed.

    – Pete Wall
    Nov 23 '18 at 21:30











  • I've voted for that, thanks very much! can I use the timezone to get it to display in UTC at the same time?

    – Pete Wall
    Nov 23 '18 at 21:38


















1















I'm trying to get data out of JIRA and into a table. I have got the API request working and I have got almost all the data out of JIRA and into the table that I need, I just can't seem to get the created date out as it is in a datetime object within the array and doesn't have a proper format.



    foreach ($ret->issues as $issue)
{
$date = new DateTime($issue->fields->created->date);
$date = $date->format('Y-m-d');
echo '<tr>
<td>'.$issue->fields->status->name.'</td>
<td>'.$date.'</td>
<td>'.$issue->fields->priority->name.'</td>
<td>'.$issue->fields->summary.'</td>
<td>'.$issue->fields->assignee->displayName.'</td>
</tr>';
}


That is the PHP code for building the table, as you can see I've tried to format it with DateTime.



Here is the array if I die on $issue->fields->created



    object(DateTime)#318 (3) {
["date"]=>
string(26) "2018-10-22 12:47:02.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-04:00"
}


I just can't seem to get that data out as $issue->fields->created->date shows me:



PHP Fatal error:  Cannot use object of type DateTime as array


Which is why I tried to format it as above. Now I get:



PHP Notice:  Undefined property: DateTime::$date


Any ideas?










share|improve this question

























  • $date = $issue->fields->created; ? It appears to already be a DateTime object.

    – rickdenhaan
    Nov 23 '18 at 21:12











  • It does, I need to use that data but I don't know how to.

    – Pete Wall
    Nov 23 '18 at 21:21











  • Looks like you could just use $issue->fields->created->format('Y-m-d') inside your echo

    – rickdenhaan
    Nov 23 '18 at 21:25











  • @rickdenhaan, please set that as the answer and I will vote for it! I had tried this method but I did $issue->fields->created->date->format('Y-m-d') which failed.

    – Pete Wall
    Nov 23 '18 at 21:30











  • I've voted for that, thanks very much! can I use the timezone to get it to display in UTC at the same time?

    – Pete Wall
    Nov 23 '18 at 21:38














1












1








1








I'm trying to get data out of JIRA and into a table. I have got the API request working and I have got almost all the data out of JIRA and into the table that I need, I just can't seem to get the created date out as it is in a datetime object within the array and doesn't have a proper format.



    foreach ($ret->issues as $issue)
{
$date = new DateTime($issue->fields->created->date);
$date = $date->format('Y-m-d');
echo '<tr>
<td>'.$issue->fields->status->name.'</td>
<td>'.$date.'</td>
<td>'.$issue->fields->priority->name.'</td>
<td>'.$issue->fields->summary.'</td>
<td>'.$issue->fields->assignee->displayName.'</td>
</tr>';
}


That is the PHP code for building the table, as you can see I've tried to format it with DateTime.



Here is the array if I die on $issue->fields->created



    object(DateTime)#318 (3) {
["date"]=>
string(26) "2018-10-22 12:47:02.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-04:00"
}


I just can't seem to get that data out as $issue->fields->created->date shows me:



PHP Fatal error:  Cannot use object of type DateTime as array


Which is why I tried to format it as above. Now I get:



PHP Notice:  Undefined property: DateTime::$date


Any ideas?










share|improve this question
















I'm trying to get data out of JIRA and into a table. I have got the API request working and I have got almost all the data out of JIRA and into the table that I need, I just can't seem to get the created date out as it is in a datetime object within the array and doesn't have a proper format.



    foreach ($ret->issues as $issue)
{
$date = new DateTime($issue->fields->created->date);
$date = $date->format('Y-m-d');
echo '<tr>
<td>'.$issue->fields->status->name.'</td>
<td>'.$date.'</td>
<td>'.$issue->fields->priority->name.'</td>
<td>'.$issue->fields->summary.'</td>
<td>'.$issue->fields->assignee->displayName.'</td>
</tr>';
}


That is the PHP code for building the table, as you can see I've tried to format it with DateTime.



Here is the array if I die on $issue->fields->created



    object(DateTime)#318 (3) {
["date"]=>
string(26) "2018-10-22 12:47:02.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-04:00"
}


I just can't seem to get that data out as $issue->fields->created->date shows me:



PHP Fatal error:  Cannot use object of type DateTime as array


Which is why I tried to format it as above. Now I get:



PHP Notice:  Undefined property: DateTime::$date


Any ideas?







php datetime jira






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 21:38









Funk Forty Niner

1




1










asked Nov 23 '18 at 21:10









Pete WallPete Wall

258




258













  • $date = $issue->fields->created; ? It appears to already be a DateTime object.

    – rickdenhaan
    Nov 23 '18 at 21:12











  • It does, I need to use that data but I don't know how to.

    – Pete Wall
    Nov 23 '18 at 21:21











  • Looks like you could just use $issue->fields->created->format('Y-m-d') inside your echo

    – rickdenhaan
    Nov 23 '18 at 21:25











  • @rickdenhaan, please set that as the answer and I will vote for it! I had tried this method but I did $issue->fields->created->date->format('Y-m-d') which failed.

    – Pete Wall
    Nov 23 '18 at 21:30











  • I've voted for that, thanks very much! can I use the timezone to get it to display in UTC at the same time?

    – Pete Wall
    Nov 23 '18 at 21:38



















  • $date = $issue->fields->created; ? It appears to already be a DateTime object.

    – rickdenhaan
    Nov 23 '18 at 21:12











  • It does, I need to use that data but I don't know how to.

    – Pete Wall
    Nov 23 '18 at 21:21











  • Looks like you could just use $issue->fields->created->format('Y-m-d') inside your echo

    – rickdenhaan
    Nov 23 '18 at 21:25











  • @rickdenhaan, please set that as the answer and I will vote for it! I had tried this method but I did $issue->fields->created->date->format('Y-m-d') which failed.

    – Pete Wall
    Nov 23 '18 at 21:30











  • I've voted for that, thanks very much! can I use the timezone to get it to display in UTC at the same time?

    – Pete Wall
    Nov 23 '18 at 21:38

















$date = $issue->fields->created; ? It appears to already be a DateTime object.

– rickdenhaan
Nov 23 '18 at 21:12





$date = $issue->fields->created; ? It appears to already be a DateTime object.

– rickdenhaan
Nov 23 '18 at 21:12













It does, I need to use that data but I don't know how to.

– Pete Wall
Nov 23 '18 at 21:21





It does, I need to use that data but I don't know how to.

– Pete Wall
Nov 23 '18 at 21:21













Looks like you could just use $issue->fields->created->format('Y-m-d') inside your echo

– rickdenhaan
Nov 23 '18 at 21:25





Looks like you could just use $issue->fields->created->format('Y-m-d') inside your echo

– rickdenhaan
Nov 23 '18 at 21:25













@rickdenhaan, please set that as the answer and I will vote for it! I had tried this method but I did $issue->fields->created->date->format('Y-m-d') which failed.

– Pete Wall
Nov 23 '18 at 21:30





@rickdenhaan, please set that as the answer and I will vote for it! I had tried this method but I did $issue->fields->created->date->format('Y-m-d') which failed.

– Pete Wall
Nov 23 '18 at 21:30













I've voted for that, thanks very much! can I use the timezone to get it to display in UTC at the same time?

– Pete Wall
Nov 23 '18 at 21:38





I've voted for that, thanks very much! can I use the timezone to get it to display in UTC at the same time?

– Pete Wall
Nov 23 '18 at 21:38












1 Answer
1






active

oldest

votes


















1














$issue->fields->created is already a DateTime object. To format that as Y-m-d format, you can simply call format() on that directly:



echo '<tr>
<td>'.$issue->fields->status->name.'</td>
<td>'.$issue->fields->created->format('Y-m-d').'</td>
<td>'.$issue->fields->priority->name.'</td>
<td>'.$issue->fields->summary.'</td>
<td>'.$issue->fields->assignee->displayName.'</td>
</tr>';


If you want to convert it to a different timezone, you can do that as well:



$issue->fields->created->setTimezone(new DateTimeZone("UTC"))->format('Y-m-d')





share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452973%2fphp-issues-with-datetime-in-array-from-jira-api%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    $issue->fields->created is already a DateTime object. To format that as Y-m-d format, you can simply call format() on that directly:



    echo '<tr>
    <td>'.$issue->fields->status->name.'</td>
    <td>'.$issue->fields->created->format('Y-m-d').'</td>
    <td>'.$issue->fields->priority->name.'</td>
    <td>'.$issue->fields->summary.'</td>
    <td>'.$issue->fields->assignee->displayName.'</td>
    </tr>';


    If you want to convert it to a different timezone, you can do that as well:



    $issue->fields->created->setTimezone(new DateTimeZone("UTC"))->format('Y-m-d')





    share|improve this answer






























      1














      $issue->fields->created is already a DateTime object. To format that as Y-m-d format, you can simply call format() on that directly:



      echo '<tr>
      <td>'.$issue->fields->status->name.'</td>
      <td>'.$issue->fields->created->format('Y-m-d').'</td>
      <td>'.$issue->fields->priority->name.'</td>
      <td>'.$issue->fields->summary.'</td>
      <td>'.$issue->fields->assignee->displayName.'</td>
      </tr>';


      If you want to convert it to a different timezone, you can do that as well:



      $issue->fields->created->setTimezone(new DateTimeZone("UTC"))->format('Y-m-d')





      share|improve this answer




























        1












        1








        1







        $issue->fields->created is already a DateTime object. To format that as Y-m-d format, you can simply call format() on that directly:



        echo '<tr>
        <td>'.$issue->fields->status->name.'</td>
        <td>'.$issue->fields->created->format('Y-m-d').'</td>
        <td>'.$issue->fields->priority->name.'</td>
        <td>'.$issue->fields->summary.'</td>
        <td>'.$issue->fields->assignee->displayName.'</td>
        </tr>';


        If you want to convert it to a different timezone, you can do that as well:



        $issue->fields->created->setTimezone(new DateTimeZone("UTC"))->format('Y-m-d')





        share|improve this answer















        $issue->fields->created is already a DateTime object. To format that as Y-m-d format, you can simply call format() on that directly:



        echo '<tr>
        <td>'.$issue->fields->status->name.'</td>
        <td>'.$issue->fields->created->format('Y-m-d').'</td>
        <td>'.$issue->fields->priority->name.'</td>
        <td>'.$issue->fields->summary.'</td>
        <td>'.$issue->fields->assignee->displayName.'</td>
        </tr>';


        If you want to convert it to a different timezone, you can do that as well:



        $issue->fields->created->setTimezone(new DateTimeZone("UTC"))->format('Y-m-d')






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 21:43

























        answered Nov 23 '18 at 21:33









        rickdenhaanrickdenhaan

        6,1261424




        6,1261424
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452973%2fphp-issues-with-datetime-in-array-from-jira-api%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()