AWS SDK for PHP – How to get creation date of a file

Question:

I have working code which returns all the files under s3 bucket. I have to get today’s uploaded files for further processing.

Code to get files :

print_r($object['LastModified']) outputs as :

I am not able to access date key.

Answer:

LastModified is an instance of Aws\Api\DateTimeResult class, since DateTimeResult extends \DateTime object, just use format method as you would normally do when working with standard DateTime objects.

echo $object['LastModified']->format(\DateTime::ISO8601)

Read here for more formatting options.

P.S. $object['LastModified']->date will not work because its not designed to be accessed directly.

Leave a Reply