2017-01-10 22 views
4

日のb/w日数を調べようとしています。以下は、私がUNIX上で完全に動作しているコードです。Bashを使用してAIXで2つの日付の間の日数を計算します。

date1=$(date "+%m/%d/%y") 
temp1=4/8/24 
echo $((($(date -u -d $temp1 +%s) - $(date -u -d $date1 +%s))/86400)) 

私はAIXボックスにスクリプト上で実行しています、私はエラーの下に取得しています:

date: Not a recognized flag: d

Usage: date [-u] [+"Field Descriptors"]

date: Not a recognized flag: d

Usage: date [-u] [+"Field Descriptors"]

(-)/86400: syntax error: operand expected (error token is ")/86400")`

それはPRODのENVだと私はそれ上の任意のパックをインストールするには管理者のアクセス権を持っていません。

+0

あなたはPerlやAWKへのアクセス権を持っていますか?見てください:http://unix.ittoolbox.com/groups/technical-functional/unixadmin-l/shell-script-to-find-noofdays-between-two-dates-in-aix-server-5591705 – Cyrus

+0

ありますawk NOT GAWK on aixボックス。 – user0

+0

AIX上に日付のフラグdがないようです。 AIXの日付コマンドに関する情報を参照してください。https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds2/date.htm –

答えて

1

これは、月は今年の1/12であることを前提としていて、あなたが適切な4桁 年を使用している:

#!/usr/bin/awk -f 
function mktm(datespec) { 
    split(datespec, q, "/") 
    return \ 
    (q[3] - 1970) * 60 * 60 * 24 * 365.25 + \ 
    (q[1] - 1) * 60 * 60 * 24 * 365.25/12 + \ 
    (q[2] - 1) * 60 * 60 * 24 
} 
function ceil(x) { 
    y = int(x); return y < x ? y + 1 : y 
} 
BEGIN { 
    srand() 
    print ceil((mktm(ARGV[1]) - srand())/(60 * 60 * 24)) 
} 
関連する問題