Skip to content

Instantly share code, notes, and snippets.

@mikeananev
Created July 19, 2022 19:11
Show Gist options
  • Select an option

  • Save mikeananev/6afeb55fa87a05edc98107ca0d0b85c0 to your computer and use it in GitHub Desktop.

Select an option

Save mikeananev/6afeb55fa87a05edc98107ca0d0b85c0 to your computer and use it in GitHub Desktop.
Calculate difference in days between two dates.
(defn diff-between-days
"Calculate difference in days between two dates."
[date1 date2]
(let [df (DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ss.SSSxxxx" Locale/ROOT)
d1 (if (string? date1) (ZonedDateTime/parse date1 df) date1)
d2 (if (string? date2) (ZonedDateTime/parse date2 df) date2)]
(.between ChronoUnit/DAYS d1 d2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment