ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 日期格式处理及求两个日期之间天数

日期格式处理及求两个日期之间天数

原创 Linux操作系统 作者:cqubityj 时间:2009-04-22 11:55:46 0 删除 编辑
#!/bin/ksh
###########################################################################
# Date calculations using Korn shell (ksh88)
# Tapani Tarvainen July 1998, May 2000
# This code is in the public domain.
# Julian Day Number from calendar date
date2julian() # day month year
{
typeset -i day month year tmpmonth tmpyear
day=$1; month=$2; year=$3
((tmpmonth = 12 * year + month - 3))
((tmpyear = tmpmonth / 12))
print $(( (734 * tmpmonth + 15) / 24 - 2 * tmpyear + \
tmpyear/4 - tmpyear/100 + tmpyear/400 + day + 1721119 ))

}

###
# Matt's Added formatting
###

# Store input dates
date1=$1
date2=$2

# Get the dates into their respective fields. Uncomment the format of
# date input being used.

# YYYYMMDD
year1=${date1%????}; mmdd1=${date1#????}; month1=${mmdd1%??}; day1=${mmdd1#??}
year2=${date2%????}; mmdd2=${date2#????}; month2=${mmdd2%??}; day2=${mmdd2#??}

# YYYY/MM/DD or YYYY/M/D
#print $date1 |IFS=/ read year1 month1 day1
#print $date2 |IFS=/ read year2 month2 day2

# MM/DD/YY or M/D/YYYY
#print $date1 |IFS=/ read month1 year1 day1
#print $date2 |IFS=/ read month2 year2 day2

# Calculate and print the difference between dates (date2 - date1)
print -- "$(($(date2julian $day2 $month2 $year2) - $(date2julian $day1 \
$month1 $year1)))"

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/228190/viewspace-591395/,如需转载,请注明出处,否则将追究法律责任。

上一篇: dbms_xplan in 10g(ZT)
请登录后发表评论 登录
全部评论

注册时间:2007-12-19

  • 博文量
    133
  • 访问量
    429060