homepage Welcome to WebmasterWorld Guest from 54.226.93.128
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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




msg:4479564
 8:12 pm on Jul 27, 2012 (gmt 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

 

ergophobe




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

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




msg:4479801
 10:03 pm on Jul 28, 2012 (gmt 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

ergophobe




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

what is the code on line 126?

hozyali




msg:4479872
 9:16 am on Jul 29, 2012 (gmt 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')
ergophobe




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

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

hozyali




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

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

ergophobe




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved