I hate date/time math!
I got something mixed up and it turns out going to be a extra 24 hours before my partner lands.
I got something mixed up and it turns out going to be a extra 24 hours before my partner lands.
@rain I used to until I realized that GNU date and GNU bash can work out dates for you.
$ date -d 'now + 3 weeks'
Wed 07 Aug 2024 15:54:01 UTC
$ date -d 'Aug 4 + 3 weeks'
Sun 25 Aug 2024 00:00:00 UTC
$ date -d 'Jan 1 1984 + 3 weeks'
Sun 22 Jan 1984 00:00:00 UTC
You can also write a bash function that calculates dates in days;
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
echo $(( (d2 - d1) / 86400 )) days
}
$ datediff '1 Aug' '1 Nov'
91 days
Or hours;
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
echo $(( (d2 - d1) / 3600 )) hours
}
$ datediff '1 Jun 2024 16:00 UTC' '3 Jun 2024 10:00 UTC'
42 hours
$ date -d 'now + 3 weeks'
Wed 07 Aug 2024 15:54:01 UTC
$ date -d 'Aug 4 + 3 weeks'
Sun 25 Aug 2024 00:00:00 UTC
$ date -d 'Jan 1 1984 + 3 weeks'
Sun 22 Jan 1984 00:00:00 UTC
You can also write a bash function that calculates dates in days;
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
echo $(( (d2 - d1) / 86400 )) days
}
$ datediff '1 Aug' '1 Nov'
91 days
Or hours;
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
echo $(( (d2 - d1) / 3600 )) hours
}
$ datediff '1 Jun 2024 16:00 UTC' '3 Jun 2024 10:00 UTC'
42 hours