kenw232 Posted May 13, 2016 Share Posted May 13, 2016 Can someone tell me how to get this [date] into a string variable? I'm not smart. Thanks. print_r($aContactToImport[LastUpdated]); Gives: DateTime Object ( [date] => 2016-05-04 12:08:18.000000 [timezone_type] => 3 [timezone] => UTC ) echo $aContactToImport[LastUpdated][date]; Gives: Fatal error: Cannot use object of type DateTime as array in whatever.cgi on line 123 Quote Link to comment https://forums.phpfreaks.com/topic/301185-cant-access-datestamp-in-array-help/ Share on other sites More sharing options...
kicken Posted May 13, 2016 Share Posted May 13, 2016 Your value is an DateTime object, not an array. The keys it shows when you run it through print_r / var_dump do not actually exist, they just show for debugging. To get a string version of the date, you need to call the format method. Also, you need to quote your array key names. For example: $dateString = $aContactToImport['LastUpdate']->format('Y-m-d H:i:s'); Quote Link to comment https://forums.phpfreaks.com/topic/301185-cant-access-datestamp-in-array-help/#findComment-1532990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.