PHP Issues with DateTime in array from JIRA api
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
|
show 3 more comments
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
$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 yourecho
– 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
|
show 3 more comments
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
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
php datetime jira
edited Nov 23 '18 at 21:38
Funk Forty Niner
80.5k1247101
80.5k1247101
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 yourecho
– 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
|
show 3 more comments
$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 yourecho
– 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
|
show 3 more comments
1 Answer
1
active
oldest
votes
$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')
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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')
add a comment |
$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')
add a comment |
$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')
$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')
edited Nov 23 '18 at 21:43
answered Nov 23 '18 at 21:33
rickdenhaanrickdenhaan
5,4961321
5,4961321
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$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 yourecho
– 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