1

I have a list of data let say

record = ['Tuesday','2018-08-29'] 

and I try to send it to google sheet through

sheet.insert_row(record,index)

and I am successfully receiving it on my gsheet but the issue is, that on the gsheet I am getting a date as a string and I can not apply any formula on it. I try to convert the string to date format

import datetime


record[1] = datetime.datetime.strptime(record[1], '%Y-%m-%d')

but then on using insert_row is giving me error that

TypeError: Object of type datetime is not JSON serializable
Muhammad Usman Bashir
  • 1,441
  • 2
  • 14
  • 43

1 Answers1

1

As per Google Sheets API Docs, you must format your date as a float of days since the Google Sheets epoch of December 30, 1899.

For instance, in my code I am working with Pandas timestamps but you can work with another timestamp datatype as you please:

time = (pd.to_datetime(time) - pd.datetime(1899, 12, 30)) / pd.to_timedelta(1, unit='D')

Upon passing this through to API into a Google sheet with the column formatted properly, you will get a google datetime type.

ddm-j
  • 403
  • 1
  • 3
  • 18