I often want to make some quick date calculations, such as:
- What is the difference between these two dates?
- What is the date n weeks after this other date?
I usually open a calendar and count the days, but I think there should be a program/script that I can use to do these kinds of calculations. Any suggestions?
Best Answer
The "n weeks after a date" is easy with GNU date(1):
I don't know of a simple way to calculate the difference between two dates, but you can wrap a little logic around date(1) with a shell function.
Swap
d1
andd2
if you want the date calculation the other way, or get a bit fancier to make it not matter. Furthermore, in case there is a non-DST to DST transition in the interval, one of the days will be only 23 hours long; you can compensate by adding ½ day to the sum.