There's a solution that almost works: use the %s
date format of GNU date, which prints the number of seconds since 1970-01-01 00:00. These can be subtracted to find the time difference between two dates.
echo $(( ($(date -d 2010-06
为了计算留存,需要知道多个从时间差,来获取不同的时间点。 以下代码在输入值与当前值,在同一月份时,不会有问题。但是如果是夸月份回溯数据,那么就会出现较大的问题。
#Date variables for
if [ -n "$1" ]; then
TODAY=`date -d "" +"%Y%m%d"`
base=$(($TODAY-$1))
elif [ -z "${DAYAGO1}" ]; then
base=0
fi
arr=($base $(($base+1)) $(($base+2)) $(($base+8)) $(($base+31)))
dag=(0 1 2 8 31)
for i in {0..4}; do
echo $i
echo ${dag[$i]}
echo ${arr[$i]}
export "DAYAGO${dag[$i]}"=`date -d "${arr[$i]} days ago" +"%Y%m%d"`
done
为了修正bug,可以参考
http://stackoverflow.com/questions/3385003/shell-script-to-get-difference-in-two-dates
There's a solution that almost works: use the %s
date format of GNU date, which prints the number of seconds since 1970-01-01 00:00. These can be subtracted to find the time difference between two dates.
echo $(( ($(date -d 2010-06