Contents
How do I get previous month Shell?
How to get first date of last month and last date of last month in Linux or Bash – Quora. First day of month is always the first, so it is easy: $ date -d “month ago” “+%Y/%m/01”
How do I get the last date of the month in Unix?
For example:
- Start with the current date ( date ) -> 2017-03-06.
- Set that date to the 1st day of its month ( -v1d ) -> 2017-03-01.
- Subtract one day from that ( -v-1d) -> 2017-02-28.
- Format the date ( +%d%b%Y ) -> 28Feb2017.