Last active
March 20, 2019 06:40
-
-
Save sursir/a4e6d5dc1a4ec8e08a305e18fa9bb35e to your computer and use it in GitHub Desktop.
shell date last month first day of last month last day of last month
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
CT='2019-02-31' # init date **When LAST DAY (end of month)** | |
date -d "$CT" +%Y-%m-%d | |
date -d "$CT last month" +%Y-%m-%d # terrible last month | |
# last month day 1 | |
date -d "$(date -d "$CT" +%Y-%m-01) last month" +%Y-%m-%d #fixed | |
# -2 month | |
date -d "$(date -d "$CT" +%Y-%m-01) -2 month" +%Y-%m-%d | |
# -3 month | |
date -d "$(date -d "$CT" +%Y-%m-01) -3 month" +%Y.%m | |
# last day of last month | |
date -d "$(date -d "$(date -d "$CT" +%Y-%m-01) last day")" +%Y-%m-%d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment