Search code examples
clojurejodatimeclj-time

Get difference between DateTime instances with clj-time


I am trying to calculate the difference between two DateTime instances using clj-time. I looked through the documentation and found clj-time.core/minus and clj-time.core/minus- but both require an instance of org.joda.time.ReadablePeriod and not one of DateTime. I would prefer to use cli-time, but if no solution exists, what would be the cleanest method of calculating the delta using Joda Time?

Thank you for the help.


Solution

  • I use this snippet very often in my daily work:

    (ns project.namespace1
      (:require [clj-time
                  [core :as t]] )
    
    (let [start-time (t/now)]
      ... do lots of work ...
      (t/in-millis (t/interval start-time (t/now))))