Shell:bash date before and after day based on a specified date

Source: Internet
Author: User

Tag: Date

####################################################################### Copyright C # # All rights Reserved # # Name : yestoday.sh# Author:canux [email protected] # # version:v1.0 # time:wed (04:37:37 PM cst# Description : ########################################################################!/bin/bashif ["$" = ""]then DATE_NO= " Date +%y%m%d ' curday= ' date +%d ' curmonth= ' date +%m ' curyear= ' date +%y ' else date_no=$1 curyear= ' echo $ | awk ' {print substr ($0,1,4)} ' Curmonth= ' echo $ | awk ' {print substr ($0,5,2)} ' curday= ' echo $ | awk ' {print substr ($0,7,2)} ' filastyear= ' expr $CURYEAR-1 ' If [[$ (10# $CURMONTH)]-eq 1]]then lastmonth=12else lastmonth = ' Expr $CURMONTH-1 ' fiif [[$LASTMONTH-ge 1]] && [[$LASTMONTH-le 9]]then lastmonth=0$lastmonthelse Lastmonth = $LASTMONTHfiNUM 1= ' cal $LASTMONTH $CURYEAR | awk ' Nr==6{print $NF} ' num2= ' cal $LASTMONTH $CURYEAR | awk ' Nr==7{print $NF} ' num3= ' cal $LASTMONTH $CURYEAR | awk ' Nr==8{print $NF} ' if [[$NUM 3-ne 0]]Then lmlastday= $NUM 3elif [[$NUM 3-eq 0]] && [[$NUM 2-ne 0]]then lmlastday= $NUM 2else lmlastday= $NUM 1fiif [[$ ( 10# $CURDAY))-eq 1]] then if [[$ ((10# $CURMONTH))-eq 1] "then lastdate= $LASTYEAR $lastmonth$lmlastday Else lastdate= $CUR Year$lastmonth$lmlastday fielse lastdate= ' expr $DATE _no-1 ' Fiecho $LASTDATE ######################################## ############################### Copyright C # # All rights Reserved # # name:tomorrow.sh# Author:canux [EMAIL PR Otected] # # version:v1.0 # time:wed 04:52:14 PM cst# Description: ######################################### ###############################!/bin/bashif ["$ $" = ""]then curdate= ' date +%y%m%d ' curday= ' date +%d ' curmonth= ' date +%m ' curyear= ' date +%y ' curhour= ' date +%h ' curmin= ' date +%m ' else curdate=$8 curyear= ' echo $ | awk ' {print substr ($0,1,4)} ' curmonth= ' echo | awk ' {print substr ($0,endhour,2)} ' curday= ' echo | awk ' {print substr ($0,7,2)} ' finextyear= ' expr $CURYEAR + 1 ' if [[$ (10# $CURMONTH))-eq]]then nextmonth=1else nextmonth= ' expr $CURMONTH + 1 ' fiif [[$ ((10# $NEXTMONTH))-ge 1]] && [[$ (10# $N Extmonth))-le 9]]then nextmonth=0$ ((10# $NEXTMONTH)) Else nextmonth= $NEXTMONTHfi #the last day of curent monthnum1= ' Cal $C Urmonth $CURYEAR | awk ' Nr==6{print $NF} ' num2= ' cal $CURMONTH $CURYEAR | awk ' Nr==7{print $NF} ' num3= ' cal $CURMONTH $CURYEAR | awk ' Nr==8{print $NF} ' if [[$NUM 3-ne 0]]then lastday= $NUM 3elif [[$NUM 3-eq 0]] && [[$NUM 2-ne 0]]then lastd ay= $NUM 2else lastday= $NUM 1fiif [[$ ((10# $CURMONTH)-eq]] && [[$ ((10# $CURDAY))-eq]]then nextdate=${nexty Ear}0101elif [[$ ((10# $CURDAY))-eq $ ((10# $LASTDAY))]]then nextdate=${curyear}${nextmonth}01else nextdate= ' expr $ Curdate + 1 ' fiecho $NEXTDATE

Shell:bash gets the day before and after date based on the specified date

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.