A date loop that is useful in processing some data that is stored by date. Especially testing and recording, deleting, reprocessing data. However, if you encounter a situation such as the span of a month, simply using a numerical cycle is not possible.
This shell can be used to handle the data for a number of days.
The code is as follows |
Copy Code |
#!/usr/bin/env Bash #author: Andy Zhou #Date: 2013.8.6 SOURCE dateutil.sh begin=20130701 end=20130904 For ((d= $begin; d<= $end; d= ' Getnextday $d ')); Todo echo "Date:" $d #. myshell.sh $d |
Date Tool dateutil.sh:
The code is as follows |
Copy Code |
#/usr/bin/env bash #author: Andy Zhou #date: 2013.8.2 Getnextday () { #date-D " 2013-09-10 +1 Day "+%y-%m-%d date-d" $ +1 Day "+%y%m%d } Getyearmonth () { ; Date +%y%m--date=$1 #shortdate } Getday () { date +%d--date=$1 #shortdat E } Long_date () { date +%y-%m-%d--date=$1 #shortdate } Short_date () { & nbsp; Date +%y%m%d--date=$1 #longdate } Long_yesterday () { date--date= ' 1 day ago ' +%y-%m-%d } Yesterday () { date--date= ' 1 day ago ' +%y%m%d } Lo Ng_today () { date +%y-%m-%d } Today () { date +%y%m%d }< br> Now () { date ' +%y-%m-%d%h:%m:%s ' } Last_month () { date --date= ' 1 month ago ' +%y%m ' } Year () { date +%y } Month () { &nb sp; date +%m } Sec2date () { date-d "1970-01-01 UTC $ Seconds" "+%y% m%d ' } Sec2datetime () { date-d "1970-01-01 UTC $ Seconds" "+%y%m%d%h:%m:%s" } |