Created
September 7, 2017 08:43
-
-
Save kentarosasaki/ef3f24ecfdc0cd2d4024dd70f7c52307 to your computer and use it in GitHub Desktop.
Bash で月初と月末を表示する方法 ref: http://qiita.com/kentarosasaki/items/afa19808758737d3ce17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 今月初め | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m01"`") | |
20170901 | |
# 先月初め | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m01"` 1 month ago") | |
20170801 | |
# 来月初め | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m01"` + 1 month") | |
20171001 | |
# 今月終わり | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m01"` 1 days ago + 1 month") | |
20170930 | |
# 先月終わり | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m01"` 1 days ago") | |
20170831 | |
# 来月終わり | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m01"` 1 days ago + 2 month") | |
20171031 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 今月2日目 | |
$ echo $(date +"%Y%m%d" -d"`date +"%Y%m02"`") | |
20170902 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment