Well,
date -d @_number_
is to parse _number_ as seconds from the epoch, on the other hand
date +%s
it to obtain seconds from the epoch. If you combine these two, you can make date based loop in BASH script easily:
# $1: start date
# $2: end date
# $3: date format (optional)
print_date_range () {
for (( d=$(date -d $1 +%s);
d<=$(date -d $2 +%s);
d+=86400)); do
date -d @$d ${3++"$3"}
done
}
print_date_range is a function to display date between specified range. You may specify date format in strftime(3) format. e.g.:
$ print_date_range now tomorrow
Wed Mar 7 12:06:32 JST 2007
Thu Mar 8 12:06:32 JST 2007
$ print_date_range "2007-03-07" "2007-03-08" "%Y/%m/%d"
2007/03/07
2007/03/08
0 件のコメント:
コメントを投稿