Hi all... I'm looking for a simply way, to calculate the diff. between two dates ... in Days ! For example>
import times
let auj = format(now(), "d/MM/yyyy -- HH:mm") # Today's date... let deb = parse("04-09-2019", "dd-MM-yyyy") #an 'older' date... echo deb.format("dd-MM-yyyy")
Actually, the result will be : 54
Very thanks.
Solution:
import times
let auj = now()
let deb = parse("04-09-2019", "dd-MM-yyyy")
echo (auj - deb).inDays
Keep in mind that this assumes 24-hour days.Don't think there's an exposed impl, but here you go:
proc julian*(year, month, day: int): int =
let a = (14 - month) div 12 # See calendar FAQ$2.16.1
let y = year + 4800 - a
let m = month + 12 * a - 3
(day + (153 * m + 2) div 5 + y * 365 +
y div 4 - y div 100 + y div 400 - 32045)
echo julian(2022, 1, 28) - julian(1970, 1, 1) # 19020
When I ran date +%s just now I got 1643395370 divided by 86400 = 19020.7797453 which is just about right (in UTC) (18:42:50).