Welcome to WebmasterWorld Guest from 54.147.44.13

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

recursive data with a lot of variables - cant display what I need

     
8:12 pm on Jul 27, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 7, 2008
posts: 93
votes: 0


Hi,

I am using braintree payments and in a place I am calling a transaction details from it. It returns with recursive arrays and a lot of data from which I need only a few values. For example, I want to get subscription start and end time. If write this code

print_r($transaction->subscriptionDetails->_attributes['billingPeriodEndDate']);


It returns the values like this
DateTime Object ( [date] => 2013-07-25 00:00:00 [timezone_type] => 3 [timezone] => UTC )


From the above output, I only want the date, to be displayed. I tried all the options, but off course I am doing something wrong still.

Can someone please tell me what should be the write call if I want to display the date only from the above output?

Thanks
Ali
5:25 pm on July 28, 2012 (gmt 0)

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8127
votes: 88


Is it not simply

$transaction->subscriptionDetails->_attributes['billingPeriodEndDate']->date

From there it depends on what your needs are. You could truncate the string to 10 characters or you could do a double convert to get any format you want, using strtotime() to get a UNIX timestamp and then using the date() function to reformat.

You have a MySQL format date/time, so that's valid to use with strtotime() as is. So you just have

$formatted_date = date('l jS \of F Y', strtotime($transaction->subscriptionDetails->_attributes['billingPeriodEndDate']->date));

to print a date like "Saturday, 27th of July, 2012" should you be so moved.


date: [php.net...]
strtotime: [php.net...]
date/time formats: [php.net...]
10:03 pm on July 28, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 7, 2008
posts: 93
votes: 0


Thanks very much for your help. But that didn't work for me. Below is the error.

Catchable fatal error: Object of class DateTime could not be converted to string in /var/www/html/wp-content/themes/#*$!/#*$!.php on line 126

Just FYI, I am using this code in a wordpress based website.

Please help.

Thanks
1:29 am on July 29, 2012 (gmt 0)

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8127
votes: 88


what is the code on line 126?
9:16 am on July 29, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 7, 2008
posts: 93
votes: 0


hi, I removed that and contacted the braintree about it.
they gave me below code and it worked fine :)

 echo $transaction->subscriptionDetails->billingPeriodStartDate->format('d/m/Y')
6:07 pm on July 29, 2012 (gmt 0)

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8127
votes: 88


wow... okay, you would need to know the Braintree API to figure that out.
6:32 pm on July 29, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 7, 2008
posts: 93
votes: 0


Thanks again for your help. Yeah I am working with braintree API.
1:25 am on July 30, 2012 (gmt 0)

Moderator

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8127
votes: 88


Yeah, I understood that you were working with Braintree, but who would have known that they had the ->format method on that object?

That's a lot easier than trying to manipulate the data with PHP.