LoginSignup
0
1

More than 5 years have passed since last update.

GNU coreutils > date > x週前の日付をyyyymmdd形式で取得する > date -d "20161020 - 4 weeks" "+%Y%m%d"

Last updated at Posted at 2017-01-17
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
date (GNU coreutils) 8.4
  • 10月20日の4週間後は何日か?
  • 11月2日の10日前は何日か?

などをcal -3コマンドでカレンダー表示をして「数えて」きた。

コマンドで自動計算して、yyyymmdd形式の結果を表示したい。

参考 http://unix.stackexchange.com/questions/24626/quickly-calculate-date-differences

コマンド例

以下とすればよさそう。

$ date -d "20161020 - 4 weeks" "+%Y%m%d"
20160922
$ date -d "20161020 + 4 weeks" "+%Y%m%d"
20161117
$ date -d "20180218 - 300 days" "+%Y%m%d"
20170424

(追記 2017/01/18)

  • 上記コマンドのdaysはdayでも同じ結果になった
  • プラスの場合、"+"はなくても同じ結果になった

補足

dateの使用例で日付フォーマットの指定にシングルクォーテーションを使う例もある。
ダブルクォーテーションとの違いは未消化。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1