Add column with number of days between dates in DataFrame pandas

To remove the ‘days’ text element, you can also make use of the dt() accessor for series: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.html So, df[[‘A’,’B’]] = df[[‘A’,’B’]].apply(pd.to_datetime) #if conversion required df[‘C’] = (df[‘B’] – df[‘A’]).dt.days which returns: A B C one 2014-01-01 2014-02-28 58 two 2014-02-03 2014-03-01 26

Swift days between two NSDates

You have to consider the time difference as well. For example if you compare the dates 2015-01-01 10:00 and 2015-01-02 09:00, days between those dates will return as 0 (zero) since the difference between those dates is less than 24 hours (it’s 23 hours). If your purpose is to get the exact day number between … Read more

Calculate days between two Dates in Java 8

If you want logical calendar days, use DAYS.between() method from java.time.temporal.ChronoUnit: LocalDate dateBefore; LocalDate dateAfter; long daysBetween = DAYS.between(dateBefore, dateAfter); If you want literal 24 hour days, (a duration), you can use the Duration class instead: LocalDate today = LocalDate.now() LocalDate yesterday = today.minusDays(1); // Duration oneDay = Duration.between(today, yesterday); // throws an exception Duration.between(today.atStartOfDay(), … Read more