Step 1:

vi .bashrc

write the code as below:

# calculate diference between two days
daydiff() {
    d1=$(date -d "$1" +%s)
    d2=$(date -d "$2" +%s)
    echo $(( (d1 - d2) / 86400 )) days
}

Example:

Step 2: type in " daydiff today '3 Dec' ". It will calculate the difference of days between today and Dec 3th.

創作者介紹
創作者 YT Lee's simple notes 的頭像
ytl0821

YT Lee's simple notes

ytl0821 發表在 痞客邦 留言(0) 人氣( 17 )