Home > Software engineering >  How to use S3 put_object without messing up dates?
How to use S3 put_object without messing up dates?

Time:12-03

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?

CodePudding user response:

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"

CodePudding user response:

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".

  • Related