Welcome to WebmasterWorld Guest from 107.20.5.156

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

     

hozyali

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

5+ Year Member



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

ergophobe

5:25 pm on Jul 28, 2012 (gmt 0)

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



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

hozyali

10:03 pm on Jul 28, 2012 (gmt 0)

5+ Year Member



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

ergophobe

1:29 am on Jul 29, 2012 (gmt 0)

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



what is the code on line 126?

hozyali

9:16 am on Jul 29, 2012 (gmt 0)

5+ Year Member



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')

ergophobe

6:07 pm on Jul 29, 2012 (gmt 0)

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



wow... okay, you would need to know the Braintree API to figure that out.

hozyali

6:32 pm on Jul 29, 2012 (gmt 0)

5+ Year Member



Thanks again for your help. Yeah I am working with braintree API.

ergophobe

1:25 am on Jul 30, 2012 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month