aix date 脚本_aix date 脚本_aix平台计算日期的前N天和后N天shell脚本

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/usr/bin/ksh

##############################################################

##aix平台下日期加减

##$1 源日期 格式:yyyyMMdd

##$2 时间间隔 小于28的自然数

##############################################################

DateAfter(){

##############################################################

if [ ! -n "$1" ];then

echo "Please input date(yyyyMMdd)!"

exit 0

fi

if [ ! -n "$2" ];then

echo "Please input Interval!"

exit 0

fi

##############################################################

param1len=`expr length $1`

if [ $param1len -ne 8 ];then

echo "Date Format IS WRONG,e.g yyyyMMdd"

exit 0

fi

##############################################################

if [ -n "$1" a -n "$2" ]; then

month=`echo $1|cut -c 5-6`

day=`echo $1|cut -c 7-8`

year=`echo $1|cut -c 1-4`

# Add 0 to month. This is a

# trick to make month an unpadded integer.

month=`expr $month + 0`

# Subtract one from the current day.

day=`expr $day + $2`

# If the day is 0 then determine the last

# day of the previous month.

if [ $day -eq 0 ]; then

# Find the preivous month.

month=`expr $month - 1`

# If the month is 0 then it is Dec 31 of

# the previous year.

if [ $month -eq 0 ]; then

month=12

day1=31

year=`expr $year - 1`

# If the month is not zero we need to find

# the last day of the month.

else

case $month in

1|3|5|7|8|10|12) day1=31;;

4|6|9|11) day1=30;;

2)

if [ `expr $year % 4` -eq 0 a `expr $year % 100` % -ne 0 o `expr $year % 400` -eq 0 ]; then

day1=29

else

day1=28

fi

;;

esac

day=`expr $day1 + $day`

fi

fi

if [ $day -lt 0 ]; then

# Find the preivous month.

month=`expr $month - 1`

# If the month is 0 then it is Dec 31 of

# the previous year.

if [ $month -eq 0 ]; then

month=12

day=`expr 31 + $day`

year=`expr $year - 1`

# If the month is not zero we need to find

# the last day of the month.

else

case $month in

1|3|5|7|8|10|12) day1=31;;

4|6|9|11) day1=30;;

2)

if [ `expr $year % 4` -eq 0 a `expr $year % 100` % -ne 0 o `expr $year % 400` -eq 0 ]; then

day1=29

else

day1=28

fi

;;

esac

day=`expr $day1 + $day`

fi

fi

echo "${#day}------------------------------"

echo "${#month}-----------------------------"

daylen=`expr length $day`

monthlen=`expr length $month`

if [ $daylen -lt 2 ];then

day=0$day

fi

if [ $monthlen -lt 2 ];then

month=0$month

fi

echo $year$month$day

else

date2=`date +20%y%m%d`

echo "$date2"

fi

}

d=`DateAfter $1 $2`

cat<

#########################################

#INPUT DATE --> $1 #

#INTERVAL --> $2 #

#RESULT DATE -->$d #

#########################################

BOF

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值