Ankan Das
Ankan Das

Reputation: 298

How to use S3 put_object without messing up dates?

import boto3

s3 = boto3.client('s3')

csv_records = ['"name","date"',
'"ankan","2021-12-02 14:02:40"']

body = "\n".join(csv_records)
body = str.encode(body)
s3.put_object(Bucket=bucket_name, Key=path, Body=body)

After running this code snippet, the csv (path variable has csv location dw) generated on S3 is containing the date like “2021-12-02 14:02”. Somehow, the rest of the date after the colon is not there at all.

I’ve tried debugging with and without using the str encode, but nothing works. The date is getting messed up, and it’s occurring only with the date field.

What to do here?

Upvotes: 1

Views: 211

Answers (2)

Ankan Das
Ankan Das

Reputation: 298

So Excel decided to truncate and display the date for no reason whatsoever. Just clicked on a date to realize that it was actually completely there. I guess it's a "solution" for those who might happen to face the same "problem".

Upvotes: 0

John Rotenstein
John Rotenstein

Reputation: 269826

It ran fine for me.

When I downloaded the file from S3 and printed its content, I got:

"name","date"
"ankan","2021-12-02 14:02:40"

Upvotes: 1

Related Questions