Created
January 29, 2021 06:10
-
-
Save lukethacoder/a4d35f456b7675bb80930530fea67f65 to your computer and use it in GitHub Desktop.
APEX: Get time between two Datetime instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Long dt1Long = DateTime.now().addDays(-1).getTime(); | |
Long dt2Long = DateTime.now().getTime(); | |
Long milliseconds = dt2Long - dt1Long; | |
Long seconds = milliseconds / 1000; | |
Long minutes = seconds / 60; | |
Long hours = minutes / 60; | |
Long days = hours / 24; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could expand to calculate days, months and years too if needed.
if only needing days, use
DateTime.daysBetween()
instead.