0

I am working with dataset of some historical subjects, some of them are in 1500's. I need to convert the datatype of some columns to datetime so I can calculate the difference in days. I tried pandas.to_datetime for converting strings in columns to datetime, but it returned Out of Bound error.

The issue can be reproduced by the following code:

datestring = '01-04-1595'
datenew = pd.to_datetime(datestring,format='%d-%m-%Y')

and the output error:

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1595-04-01 00:00:00

I learned that the limits of timestamp are min 1677-09-21 and max 2262-04-11, but what would be the workaround for this? The expected timestamp range that will accomodate my dataset is between 1500 to 1900.

I would like to apply the string to datetime conversion for all entries of a column.

Thank you.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Dicky
  • 1
  • 2
    When asking a code related question, the very first tag you should add is for the language that you're using. When asking a database or SQL question, the very first tag you add should be for the specific RDBMS you're using. Please [edit] your post to add the appropriate tag. For more information, see [ask]. – Ken White Oct 08 '22 at 22:48
  • Does this answer your question? [pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset](https://stackoverflow.com/questions/32888124/pandas-out-of-bounds-nanosecond-timestamp-after-offset-rollforward-plus-adding-a) – FObersteiner Oct 09 '22 at 08:23
  • see the linked duplicate: use for example Python's datetime class. – FObersteiner Oct 09 '22 at 08:24
  • example of the dataframe ? the question needs sufficient code for a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – D.L Oct 09 '22 at 15:16

0 Answers0