Skip to content

Instantly share code, notes, and snippets.

@huiliu
Created July 4, 2013 15:34
Show Gist options
  • Select an option

  • Save huiliu/5928667 to your computer and use it in GitHub Desktop.

Select an option

Save huiliu/5928667 to your computer and use it in GitHub Desktop.
求得今天前的N天的字符串,如:"20130704"
#!/bin/bash
# Use shell calculate the date interval before today
SECOND_TODAY=`date +%s`
SECOND_PER_DAY=86400
INTERVAL=7
SEQ=`seq $INTERVAL`
#set -x
for i in $SEQ
do
DATE=`echo "$SECOND_TODAY - $SECOND_PER_DAY * ${i}" | bc`
echo `date --date="@$DATE" +%Y%m%d`
done
#set +x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment