Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with date cells (using date/time serial numbers) #380

Open
Drowze opened this issue Jul 23, 2020 · 0 comments
Open

Working with date cells (using date/time serial numbers) #380

Drowze opened this issue Jul 23, 2020 · 0 comments

Comments

@Drowze
Copy link

Drowze commented Jul 23, 2020

I want to be able to seamless work with date/time cells without depending on knowing the spreadsheet locale or the cell format. While researching, I found out that Google Spreadsheets use date/times in serial format:

Google Sheets, like most other spreadsheet applications, treats date/time values as decimal values. This lets you perform arithmetic on them in formulas, so you can increment days or weeks, add or subtract two date/times, and perform other similar operations.
Google Sheets uses a form of epoch date that is commonly used in spreadsheets. The whole number portion of the value (left of the decimal) counts the days since December 30th 1899. The fractional portion (right of the decimal) counts the time as a fraction of one day. For example, January 1st 1900 at noon would be 2.5, 2 because it's two days after December 30th, 1899, and .5 because noon is half a day. February 1st 1900 at 3pm would be 33.625.

https://developers.google.com/sheets/api/guides/concepts#datetime_serial_numbers

I would like to use it, so I had a look into it:

For reading: using Worksheet#numeric_value is enough (#377 also makes this more intuitive)
For writing: I did not find a way to write a numeric value to a date/time cell and had it to write a date. Because the Worksheet#[]= method calls stringifies the value, it is always interpreted as a number literal, instead of a serial number date. (opened #379 with a proposed solution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant