Home > Software design >  How to get lapsed time over 2 days python
How to get lapsed time over 2 days python

Time:02-26

hoping you can help me solve this one. I am working on a project which involves tracking lapse time between when an order is placed and when it's delivered. The date formats of the file I'm working with is as follows: "Calendar Day :hour:minute:second"

That said, I was able to create datetime64[ns] objects for the attributes using the following code:

df["Customer placed order datetime"] = pd.to_datetime(data["Customer placed order datetime"], format='%d %H:%M:%S')
data["Delivered to consumer datetime"] = pd.to_datetime(data["Delivered to consumer datetime"], format='%d %H:%M:%S')

I am then taking the difference of when an order is delivered - when it was placed to get the total time lapse

data["lapse"] = data["Delivered to consumer datetime"] - data["Customer placed order datetime"]

This works great for orders delivered the same day, however I am running into a problem with orders placed late at night and delivered the next day. Please see example below:

Customer placed order | datetime Delivered to consumer datetime | lapse

1900-01-31 23:59:46 | 1900-01-01 01:49:07 | 31 days 01:49:21

Any suggestions on how to fix this issue?

Thanks!

CodePudding user response:

It doesn't look like there's an issue with your code. The dates you gave as an example actually have 31 days between them. Do you have a typo in your dates data?

CodePudding user response:

The example provided doesn't reflect the problem you are trying to solve. The dates in the example are a month apart from one another. Try to recreate the error using a valid example and see if the issue still persists

  • Related