Jump to content

Can't access datestamp in array - help


kenw232

Recommended Posts

 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
Link to comment
Share on other sites

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');
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.